vue-router 根据name属性判断是否拥有该路由, 留个存根, 也分享给大家
hasRoute(name, routeList) {
!routeList && (routeList = this.$router.options.routes, console.log('执行'))
for (let i = 0; i < routeList.length; i++) {
console.log(routeList[i])
if (routeList[i].name === name) {
return true
}
if (routeList[i].children) {
let flag = this.hasRoute(name, routeList[i].children)
if(flag){
return flag
}
}
}
return false
}
调用
jump(name) {
// 因为返回的是true或者false 所以直接判断了
if(!this.hasRoute(name)){
this.$message("无权限查看页面");
}else{
this.$router.push({name:name})
}
}
版权声明:本文为Lidppp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。