index.ts 455 B

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