0dc6cac0a833e07b6dc1883e6ab55b3c61ba62dd.svn-base 584 B

12345678910111213141516171819202122
  1. import store from '@/store'
  2. export default {
  3. inserted(el, binding, vnode) {
  4. const { value } = binding
  5. const roles = store.getters && store.getters.roles
  6. if (value && value instanceof Array && value.length > 0) {
  7. const permissionRoles = value
  8. const hasPermission = roles.some(role => {
  9. return permissionRoles.includes(role)
  10. })
  11. if (!hasPermission) {
  12. el.parentNode && el.parentNode.removeChild(el)
  13. }
  14. } else {
  15. throw new Error(`need roles! Like v-permission="['admin','editor']"`)
  16. }
  17. }
  18. }