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