-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue权限控制
44 lines (41 loc) · 915 Bytes
/
vue权限控制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//main.js
`let userMenu=['新开样本','埋点申请','埋点展示','权限管理']
let permissions ={'新开样本+编辑':false,'新开样本+删除':true};
//操作
Vue.directive('has',{
bind:function(el,binding){
if(!permissions[binding.value]){
el.parentNode.removeChild(el);
}
}
})
//路由
let user='123'||sessionStorage.getItem('user');
let routes,router;
if(user){
if(!userMenu.length){
routes=fullPath.filter(item=>{
return item.name!=='index'
})
}else{
fullPath.map(item=>{
if(item.name==='index'){
item.children=item.children.filter(sub=>{
return userMenu.indexOf(sub.name)>-1
})
item.redirect='/index/'+item.children[0].path; //设置子路由第一项未index默认页面
}
});
routes=fullPath;
}
router=new Router({routes})
}else{
location.href='/login'
}
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
`