File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 11import store from '@/store'
22
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
76
8- if ( value && value instanceof Array && value . length > 0 ) {
7+ if ( value && value instanceof Array ) {
8+ if ( value . length > 0 ) {
99 const permissionRoles = value
1010
1111 const hasPermission = roles . some ( role => {
@@ -15,8 +15,17 @@ export default {
1515 if ( ! hasPermission ) {
1616 el . parentNode && el . parentNode . removeChild ( el )
1717 }
18- } else {
19- throw new Error ( `need roles! Like v-permission="['admin','editor']"` )
2018 }
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 )
2130 }
2231}
You can’t perform that action at this time.
0 commit comments