鍍金池/ 問答/HTML/ vue路由權(quán)限

vue路由權(quán)限

問題是這樣的,路由結(jié)構(gòu)
//父路由
{
path:'/a',
computends:a,
meta:{auth:'a'}
}
//子路由
{
path:'/a/b'
computends:b,
}
請教下
當(dāng)父路由有權(quán)限的時候,子路由不用設(shè)置meta,就能進入/a/b這樣的路由

回答
編輯回答
爆扎

不全局攔截,在那個路由下面寫權(quán)限檢查

2017年9月30日 09:16
編輯回答
萌小萌

在【router.beforeEach((to, from, next) => {】里處理:
router.beforeEach((to, from, next) => {

let ps = to.matched
let meta = null
for (let p of ps) {
  if (p.meta) {
    meta = p.meta //獲取距離當(dāng)前頁最親的父meta
  }
}
// 判斷meta里的權(quán)限
2018年6月10日 08:49