vue监听浏览器刷新

  mounted() {
    window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
  },

  

  methods: {
    beforeunloadHandler (e) {
      e = e || window.event
      if (e) {
        e.returnValue = '关闭提示'
      }
      window.sessionStorage.setItem('a',1)
      return '关闭提示'
    },
}

  

  destroyed () {
    window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
  }

  

posted @ 2019-12-26 14:09  秋风渡明月  阅读(7671)  评论(0编辑  收藏  举报