参考:https://blog.youkuaiyun.com/KingJin_优快云_/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项目中使用路由守卫来控制页面的进出逻辑,并设置页面标题,确保应用在不同页面间切换时能正确显示对应标题,同时处理不存在页面的情况。
373

被折叠的 条评论
为什么被折叠?



