當(dāng)我掛載頁面時(shí),我添加了一個(gè) eventListner,如果用戶想要更改路由,我想將其刪除。但在我的情況下,在我更改路線后該事件仍然可用,如果我關(guān)閉選項(xiàng)卡,我仍然會(huì)收到警報(bào)。 mounted: function () { window.addEventListener("beforeunload", this.detectTabClose); }, beforeRouteLeave(to, from, next) { //gets here and the route is changed, but this event is not removed window.removeEventListener("beforeunload", this.detectTabClose, true); next(); },detectTabClose(e) { var confirmationMessage = "o/"; (e || window.event).returnValue = confirmationMessage; return confirmationMessage;},
更改路由 Vuejs 時(shí)的 removeEventListener
飲歌長嘯
2023-04-27 15:26:10