Skip to content

Commit

Permalink
update: 增加自定义指令
Browse files Browse the repository at this point in the history
  • Loading branch information
sincely committed Dec 24, 2023
1 parent a2425bb commit 62d2927
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/directives/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log(111111111)
import setupPermissionDirective from './permission'
export function setupDirectives(app) {
setupPermissionDirective(app)
}
26 changes: 26 additions & 0 deletions src/directives/permission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// import { usePermission } from '@/composables'

export default function setupPermissionDirective(app) {
// const { hasPermission } = usePermission()

// function updateElVisible(el, permission) {
// if (!permission) {
// throw new Error(`need roles: like v-permission="'admin'", v-permission="['admin', 'test]"`)
// }
// if (!hasPermission(permission)) {
// el.parentElement?.removeChild(el)
// }
// }

// const permissionDirective = {
// mounted(el, binding) {
// updateElVisible(el, binding.value)
// },
// beforeUpdate(el, binding) {
// updateElVisible(el, binding.value)
// }
// }

// app.directive('permission', permissionDirective)
console.log(app)
}
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import App from '@/App.vue'
import store from '@/store'
import router from '@/router' // 路由
import '@/styles/index.less' // 全局样式
import { setupDirectives } from './directives' // 自定义指令
async function setupApp() {
const app = createApp(App)
app.use(store)
app.use(router)
setupDirectives(app)
app.mount('#app')
app.config.performance = true
}
Expand Down

0 comments on commit 62d2927

Please sign in to comment.