vue 退出页面前弹出alert窗

    科技2025-06-04  25

    let _this = this window.onbeforeunload = function (e) { if (_this.$route.name == "XXX") { 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 } };

    该段代码放在mounted方法里

    Processed: 0.012, SQL: 8