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