vue路由拦截器
router.beforeEach((to, from, next) => {
if (to.name === "login") {
next()
return;
}
// 用户是否已登录
const info = userInfoStore()
if (!info.userToken) {
next({"name": "login"})
return;
}
// 用户是否有权限
let userRole = info.userRole
let allowRoleList = to.meta.role
if (allowRoleList.indexOf(userRole) === -1) {
next({"name": "home"})
return;
}
next()
})