File tree 1 file changed +16
-7
lines changed
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 1
1
import store from '@/store'
2
2
3
- export default {
4
- inserted ( el , binding , vnode ) {
5
- const { value } = binding
6
- const roles = store . getters && store . getters . roles
3
+ function checkPermission ( el , binding ) {
4
+ const { value } = binding
5
+ const roles = store . getters && store . getters . roles
7
6
8
- if ( value && value instanceof Array && value . length > 0 ) {
7
+ if ( value && value instanceof Array ) {
8
+ if ( value . length > 0 ) {
9
9
const permissionRoles = value
10
10
11
11
const hasPermission = roles . some ( role => {
@@ -15,8 +15,17 @@ export default {
15
15
if ( ! hasPermission ) {
16
16
el . parentNode && el . parentNode . removeChild ( el )
17
17
}
18
- } else {
19
- throw new Error ( `need roles! Like v-permission="['admin','editor']"` )
20
18
}
19
+ } else {
20
+ throw new Error ( `need roles! Like v-permission="['admin','editor']"` )
21
+ }
22
+ }
23
+
24
+ export default {
25
+ inserted ( el , binding ) {
26
+ checkPermission ( el , binding )
27
+ } ,
28
+ update ( el , binding ) {
29
+ checkPermission ( el , binding )
21
30
}
22
31
}
You can’t perform that action at this time.
0 commit comments