前置路由守卫的使用
作者:互联网
// 前置路由守卫
router.beforeEach ((to, from, next) => {
let token = localStorage.getItem ('token')
if (to.path == '/cart') {
// 判断是否登录,是否有token
if (token) {
next ()
} else {
Vue.prototype.$toast ('请先登录')
setTimeout (() => {
next ('/user')
}, 1000)
}
}
next ()
})
搜索
复制
标签:登录,前置,next,守卫,token,路由 来源: https://www.cnblogs.com/wq246679/p/16458653.html