From 62d292766f6320dc2e021ae4f40c482176beb673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E8=88=9F?= <1738248438@qq.com> Date: Sun, 24 Dec 2023 13:09:44 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/directives/index.js | 5 ++++- src/directives/permission.js | 26 ++++++++++++++++++++++++++ src/main.js | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/directives/permission.js diff --git a/src/directives/index.js b/src/directives/index.js index bdc0dac..fad052e 100644 --- a/src/directives/index.js +++ b/src/directives/index.js @@ -1 +1,4 @@ -console.log(111111111) +import setupPermissionDirective from './permission' +export function setupDirectives(app) { + setupPermissionDirective(app) +} diff --git a/src/directives/permission.js b/src/directives/permission.js new file mode 100644 index 0000000..f8ed327 --- /dev/null +++ b/src/directives/permission.js @@ -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) +} diff --git a/src/main.js b/src/main.js index 928302d..772ccb3 100644 --- a/src/main.js +++ b/src/main.js @@ -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 }