美文网首页
Vue 关闭微信浏览器(返回路由为undefined时)

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

作者: 前端召唤师 | 来源:发表于2019-07-08 16:53 被阅读0次

参考: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/>'
})

相关文章

网友评论

      本文标题:Vue 关闭微信浏览器(返回路由为undefined时)

      本文链接:https://www.haomeiwen.com/subject/ukdahctx.html