permissions.js 414 B

12345678910111213
  1. import store from '@/store'
  2. export default {
  3. inserted(element, binding) {
  4. const { value } = binding
  5. const permissions = store.getters['user/permissions']
  6. if (value && value instanceof Array && value.length > 0) {
  7. const hasPermission = permissions.some((role) => value.includes(role))
  8. if (!hasPermission)
  9. element.parentNode && element.parentNode.removeChild(element)
  10. }
  11. },
  12. }