其他分享
首页 > 其他分享> > Vue - 监听页面刷新和关闭

Vue - 监听页面刷新和关闭

作者:互联网

一,在 created中 注册 页面刷新和关闭事件 created() {  window.addEventListener('beforeunload', e => this.test(e)) }   二,事件,将你的逻辑方法加进去 methods: {  test(e) {   console.log('刷新或关闭')   // ...  } } 三,卸载注册的事件 destroyed() {  window.removeEventListener('beforeunload', e => this.test(e)) }

标签:Vue,created,window,关闭,刷新,test,beforeunload,监听,页面
来源: https://www.cnblogs.com/500m/p/12109744.html