亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改路由 Vuejs 時的 removeEventListener

更改路由 Vuejs 時的 removeEventListener

飲歌長嘯 2023-04-27 15:26:10
當我掛載頁面時,我添加了一個 eventListner,如果用戶想要更改路由,我想將其刪除。但在我的情況下,在我更改路線后該事件仍然可用,如果我關閉選項卡,我仍然會收到警報。  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;},
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經驗 獲得超11個贊

您可以刪除 beforeDestroy 掛鉤上的事件偵聽器

beforeDestroy() { 
  window.removeEventListener("beforeunload", this.detectTabClose);
},


查看完整回答
反對 回復 2023-04-27
  • 1 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號