vue 监听返回

mounted: function() {  //使用keep-alive时可以放在activated内
    if (window.history && window.history.pushState) {
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', this.listenBack, false);
    }           
},
methods: {
    listenBack() {
        if (true) { //必须有,否则可能无法关闭
           //这个可以关闭安卓系统的手机
            document.addEventListener('WeixinJSBridgeReady', function() {
          WeixinJSBridge.call(
'closeWindow');}, false); //这个可以关闭ios系统的手机,顺序不能改变 WeixinJSBridge.call('closeWindow'); } }, beforeRouteLeave(to, from, next) { window.removeEventListener('popstate', this.listenBack, false); }

猜你喜欢

转载自www.cnblogs.com/linjiangxian/p/11460831.html