当前位置: 代码迷 >> 综合 >> vue3.0中如何载入自定义指令
  详细解决方案

vue3.0中如何载入自定义指令

热度:19   发布时间:2023-11-18 12:48:34.0

main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import directives from './directives/index.js'const app = createApp(App)
// 载入自定义指令
directives(app)

directives -> index.js

// 自定义指令集
export default (app) => {/*** 自定义指令* 按钮的权限控制* 例:<el-button v-has="'fleetManage_newBranch'">新增分公司</el-button>* @params {btnData} [所有可以显示的按钮name]*/app.directive('has', (el, binding) => {let types = sessionStorage.getItem('btnData').split(',')if (!types.length) return falseif (!types.includes(binding.value)) {el.parentNode && el.parentNode.removeChild(el)}})
}