Javascript Vue/Vue bulma-n进度:进度条将永远加载到警戒/重定向中
nprogress在其他方面都可以正常工作,但在重定向到/登录时,它将永远旋转。我尝试了showProgressBar:false无效 如果用户已登录,他们将被重定向到/dashboard;如果用户未登录,他们将被重定向到/login 我的代码如下所示:Javascript Vue/Vue bulma-n进度:进度条将永远加载到警戒/重定向中,javascript,vue.js,Javascript,Vue.js,nprogress在其他方面都可以正常工作,但在重定向到/登录时,它将永远旋转。我尝试了showProgressBar:false无效 如果用户已登录,他们将被重定向到/dashboard;如果用户未登录,他们将被重定向到/login 我的代码如下所示: const routes = [ {path: '/', name: 'root', redirect: { name: 'login' }, meta: {showProgressBar: false}}, {path: '/logi
const routes = [
{path: '/', name: 'root', redirect: { name: 'login' }, meta: {showProgressBar: false}},
{path: '/login', component: LoginPage, name: 'login', beforeEnter: loggedIn, meta: {showProgressBar: false}},
{path: '/dashboard', component: DashboardPage, name: 'dashboard', meta: { requiresAuth: true }},
{path: '/editor', component: PhoneEditorPage, name: 'editor', meta: { requiresAuth: true }},
{path: '/usersettings', component: PinPasswordPage, name: 'pinpassword', meta: { requiresAuth: true }},
{path: '/callforwarding', component: CallForwardingPage, name: 'callforwarding', meta: { requiresAuth: true }},
{ name: 'dropdown', path: '/dropdown', component: Dropdown, meta: { requiresAuth: true }}
]
const router = new VueRouter({
linkActiveClass: 'active',
mode: 'hash',
routes
})
function loggedIn (to, from, next) {
const authUser = JSON.parse(window.localStorage.getItem('authUser'))
if (authUser && authUser.auth) {
next({name: 'dashboard'})
} else {
next()
}
}
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const authUser = JSON.parse(window.localStorage.getItem('authUser'))
if (authUser && authUser.auth) {
next()
} else {
next({name: 'login'})
this.nprogress.done()
}
}
next()
谢谢您的时间。在没有看到代码的情况下回答起来并不简单,但是,您可以尝试反向调用
this.nproges.done()
和next(…)
,如下所示:
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const authUser = JSON.parse(window.localStorage.getItem('authUser'))
if (authUser && authUser.auth) {
next()
} else {
this.nprogress.done(); // <- HERE
next({name: 'login'})
}
}
next()
}
router.beforeach((to,from,next)=>{
if(to.meta.requireAuth){
const authUser=JSON.parse(window.localStorage.getItem('authUser'))
if(authUser&&authUser.auth){
下一个()
}否则{
这个.nprogress.done();//在不查看代码的情况下回答起来并不简单,但是,您可以尝试将对this.nprogress.done()
和next(…)
的调用反转如下:
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const authUser = JSON.parse(window.localStorage.getItem('authUser'))
if (authUser && authUser.auth) {
next()
} else {
this.nprogress.done(); // <- HERE
next({name: 'login'})
}
}
next()
}
router.beforeach((to,from,next)=>{
if(to.meta.requireAuth){
const authUser=JSON.parse(window.localStorage.getItem('authUser'))
if(authUser&&authUser.auth){
下一个()
}否则{
this.nprogress.done();//你能在此基础上创建一个JSFIDLE吗?这对我所有的依赖项都不可行。你能在此基础上创建一个JSFIDLE吗?这对我所有的依赖项都不可行。