directive.ts 473 B

123456789101112131415161718
  1. import type { App, DirectiveBinding } from 'vue'
  2. import { hasPermission } from '@/utils/permission'
  3. export default {
  4. install(app: App<Element>) {
  5. /**
  6. * @description 自定义指令v-permissions
  7. */
  8. app.directive('permissions', {
  9. mounted(el: any, binding: DirectiveBinding) {
  10. const { value } = binding
  11. if (value)
  12. if (!hasPermission(value))
  13. el.parentNode && el.parentNode.removeChild(el)
  14. },
  15. })
  16. },
  17. }