在做vue项目时,写了如下代码,页面卡死,出现死循环,可能是逻辑有问题,大佬给理理
相关代码
mounted() {
console.log("aaa")
let _this = this
this.$router.beforeEach(function (to,from,next) {
if(to.meta.auth) {
if(window.localStorage.getItem('user')) {
console.log('路由设置了守卫,但是已经登录了');
next()
} else {
console.log('路由设置了守卫,但是我还没有登录')
console.log(_this.$router, 'sfafasdfasdf')
_this.$router.push({path:'/login'})
next({
path: to.path,
})
}
} else {
console.log("路由没有设置守卫");
next({
path: to.path
})
}
})
}
你这就一直登陆跳登陆嘛,你要当
to.path!='/login'
并且没有登陆的时候跳登陆啊。