判断用户是否登录报错
router.beforeEach((to,from,next)=>{
//判断用户是否登录
console.log("store",store.state.uInfo)
const uInfo = store.state.uInfo.userInfo
if(!uInfo.userName){
//未登录
if(to.path === "/login"){
next()
return
}
next("/login")
}else{
next()
}
})
代码走到这行的时候 就已经报错了 ,console.log("store",store.state.uInfo) 检查下你的 store 里有没有 这个 uInfo 值
userInfo写错了,userinfo这里应该是小写的,改成const uInfo = store.state.uInfo.userinfo