Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

vue动态路由切换账号的时候,addRoutes会重复添加?

vue动态路由切换账号的时候,退出登录,然后再用另外一个权限账号登录,但是这个账号的权限还是使用的上一次登录的账号权限,在查了百度之后发现要用这个方法

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const createRouter = () => new Router({
  mode: 'history',
  routes: []
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // the relevant part
}

export default router

但是我试了,在登出操作的时候调用 resetRouter()方法,再次登录的时候还是采用的上一个账号的权限,只有用location.reload()才会正确的显示当前账号的权限,这是什么原因呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

退出登录的时候调用的resetRouter方法,router没有指向vue实例里面的router,所以router实际没有改变=》权限没变,reload重新初始化vue实例,router一并重置,所以会正确显示权限。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...