**我想模拟一个路由拦截判断登陆状态true的话就正常跳转,false就跳转到登陆页面但是报错好像进入了死循环我感觉逻辑没问题啊求大神开导开导哪里出了问题**//main.jsimportVuefrom'vue'importAppfrom'./App'importrouterfrom'./router'importstorefrom'./vuex/store'Vue.config.productionTip=falserouter.beforeEach((to,from,next)=>{store.state.islogin?next():next('/log')})//storeimportVuefrom'vue'importVuexfrom'vuex'Vue.use(Vuex);conststate={islogin:false}
2 回答
噜噜哒
TA贡献1784条经验 获得超7个赞
router.beforeEach((to,from,next)=>{if(to.meta.Auth){if(store.state.islogin){next();}else{router.push({name:'login'})}}else{next();}})路由{path:'/admin',name:'admin',meta:{Auth:true,//需要登录},component:Admin('admin')}
手掌心
TA贡献1942条经验 获得超3个赞
router.beforeEach((to,from,next)=>{(store.state.islogin||to.path=='/log')?next():next('/log')})
添加回答
举报
0/150
提交
取消