router.addRoutes(currentRoute)语句和
router.currentRoute.meta关系?
实验了一下,存的是meta,取的也是同一个meta是一个数据,但是语法上有疑惑,看不懂
```export function initRouterInfo() {
const currentRoutes = router.options.routes
const rightList = store.state.rights
rightList.forEach(item => {
item.children.forEach(item => {
const itemRule = ruleMapping[item.path];
itemRule.meta = item.rights;
currentRoutes[2].children.push(itemRule)
})
})
// console.log("currentRoutes", currentRoutes)
_ **router.addRoutes(currentRoutes)**_
console.log("router添加currentRoutes",router)
}
import router from '@/router.js'
Vue.directive('permission', {
inserted: function(el, binding){
// console.log("el",el);
const action = binding.value.action
//currentRoute哪来的不知道,但是很好用,获取当前路由信息
//
console.log("route当前路由",router)
_**const rightList = router.currentRoute.meta**_
// console.log("meta不能显示吧",router.currentRoute)
const effect = binding.value.effect
if(rightList.indexOf(action) == -1){
if(effect==="disabled"){
el.disabled = true
el.classList.add('is-disabled')
}else{
el.parentNode.removeChild(el)
}
}
}
})
```