vue监听浏览器刷新

时间:2019-12-26 14:38:04   收藏:0   阅读:665
  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))
  }

  

原文:https://www.cnblogs.com/js-liqian/p/12101748.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!