index.ts 458 B

123456789101112131415
  1. import { hasPerms } from "@/utils/auth";
  2. import type { Directive, DirectiveBinding } from "vue";
  3. export const perms: Directive = {
  4. mounted(el: HTMLElement, binding: DirectiveBinding<string | Array<string>>) {
  5. const { value } = binding;
  6. if (value) {
  7. !hasPerms(value) && el.parentNode?.removeChild(el);
  8. } else {
  9. throw new Error(
  10. "[Directive: perms]: need perms! Like v-perms=\"['btn.add','btn.edit']\""
  11. );
  12. }
  13. }
  14. };