Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from vitorvargasdev/permissions.js
Last active February 10, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcorrea/93ffa07c09b20661f160723f6a780235 to your computer and use it in GitHub Desktop.
Save wilcorrea/93ffa07c09b20661f160723f6a780235 to your computer and use it in GitHub Desktop.
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