Skip to content

Commit

Permalink
refactor: 优化 v-auth 指令
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Feb 8, 2025
1 parent cf9bb77 commit 73d6ae4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/utils/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import type { App, DirectiveBinding } from 'vue'

export default function directive(app: App) {
app.directive('auth', (el: HTMLElement, binding: DirectiveBinding) => {
if (binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value)) {
el.style.display = ''
}
else {
el.style.display = 'none'
}
watch(() => binding.modifiers.all ? useAuth().authAll(binding.value) : useAuth().auth(binding.value), (val) => {
el.style.display = val ? '' : 'none'
}, {
immediate: true,
})
})
}

0 comments on commit 73d6ae4

Please sign in to comment.