-
-
Save wilcorrea/93ffa07c09b20661f160723f6a780235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $store from '../store' | |
const remove = (vnode) => vnode.elm.parentElement.removeChild(vnode.elm) | |
export default { | |
install (Vue) { | |
Vue.directive('permission', { | |
inserted (el, binding, vnode) { | |
if (binding.arg !== 'can') { | |
return | |
} | |
const permission = $store.state.user.permissions | |
if (!Array.isArray(permission)) { | |
remove(vnode) | |
return | |
} | |
if (!permission.includes(binding.value)) { | |
return | |
} | |
remove(vnode) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment