Vue - listening and off page refresh

First, the registration page refreshes and closing events created in
created() {
 window.addEventListener('beforeunload', e => this.test(e))
}
 
Second, the event will be added to the list of your logical approach
methods: {
 test(e) {
  console.log('刷新或关闭')
  // ...
 }
}
Third, the uninstallation events
destroyed() {
 window.removeEventListener('beforeunload', e => this.test(e))
}

Guess you like

Origin www.cnblogs.com/500m/p/12109744.html