可以在路由里面設置需要登錄的界面,判斷下沒有登錄就跳轉到登錄界面,登錄了就不用登錄,這里用的是一個存儲的
router.beforeEach((to, from, next) => {
if(to.matched.some( m => m.meta.auth)){
if(sessionStorage.getItem('isLogin')){
next()
}else{
next({path:'/login',query:{url: to.fullPath} })
}
}else{
next();
}
})
這里是判斷是否登錄
this.$router.push(this.$router.currentRoute.query.url)這里的代碼可以直接跳轉到需要登錄的界面