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)}})
}