Vue - 监听页面刷新和关闭


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM