vue 关闭微信浏览器(返回路由为undefined时)


参考:https://blog.csdn.net/KingJin_CSDN_/article/details/77050569

main.js:

import router from './router';

router.beforeEach((to, from, next) => {

    const toDepth = to.meta.index;
    const fromDepth = from.meta.index;

    if (to.meta.title) {
        document.title = to.meta.title;
    }

    if (toDepth == 'undefined' || toDepth == undefined) {
        let notice = '';
        if (fromDepth == 0) {
            notice = '无上一级页面,即将关闭';
        } else {
            notice = '进入页面不存在,即将关闭';
        }
        alert(notice); //必须有弹窗,否则可能无法关闭
        //这个可以关闭安卓系统的手机
        document.addEventListener('WeixinJSBridgeReady', function() {
            WeixinJSBridge.call('closeWindow');
        }, false);
        //这个可以关闭ios系统的手机
        WeixinJSBridge.call('closeWindow');
        // wx.closeWindow();
        return;
}

new Vue({
    el: '#app',
    router,
    components: {
        App
    },
    template: '<App/>'
})

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM