vue如何在用户要关闭当前网页时弹出提示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39517820/article/details/83446877

正常 js 页面处理方式

window.onbeforeunload = function (e) {
  e = e || window.event;
  // 兼容IE8和Firefox 4之前的版本
  if (e) {
    e.returnValue = '关闭提示';
  }
  // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
  return '关闭提示';
}; 

vue 中处理方式

let _this = this
    window.onbeforeunload = function (e) {
      if (_this.$route.name == "dyyPerformanceCenterSale") {
        e = e || window.event;
        // 兼容IE8和Firefox 4之前的版本
        if (e) {
          e.returnValue = '关闭提示1111';
        }
        // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
        return '关闭提示222';
      } else {
        window.onbeforeunload = null
      }
    };

猜你喜欢

转载自blog.csdn.net/qq_39517820/article/details/83446877