在路由配置中添加一个字段,它用于判断路由是否需要拦截。
{
name:'index',
path:'/index',
component:Index,
meta:{
requirtAuth:true
}
}
router.beforeEach((to,from,next) => {
if(to.meta.requirtAuth){
if(store.state.token){
next()
}else{
}
}
})