VUE项目中阻止手机物理返回键

2019-07-11  本文已影响0人  嘤夏影

直接上代码

  mounted() {
         if (window.history && window.history.pushState) {
                history.pushState(null, null, document.URL);
                window.addEventListener('popstate', this.fun, false);    //false阻止默认事件    this.fun是指返回按建实际要执行的方法
          }
  }

   destroyed(){  // 销毁时取消监听
        window.removeEventListener('popstate', this.fun, false);//false阻止默认事件
    },
上一篇下一篇

猜你喜欢

热点阅读