permissions.js 438 B

123456789101112131415161718
  1. import store from "@/store";
  2. export default {
  3. inserted(el, 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) => {
  8. return value.includes(role);
  9. });
  10. if (!hasPermission) {
  11. el.parentNode && el.parentNode.removeChild(el);
  12. }
  13. }
  14. },
  15. };