1.按鈕權限處理
/*** v-hasPermi 按鈕權限處理*/import store from '@/store'export default {inserted(el, binding, vnode) {const { value } = bindingconst all_permission = "*:*:*";const permissions = store.getters && store.getters.permissionsif (value && value instanceof Array && value.length > 0) {const permissionFlag = valueconst hasPermissions = permissions.some(permission => {return all_permission === permission || permissionFlag.includes(permission)})if (!hasPermissions) {// el.parentNode && el.parentNode.removeChild(el)el.style.display = 'none'}} else {throw new Error(`請設置操作權限按鈕值`)}}
}
2.注冊自定義指令
import hasPermi from './hasPermi'
const install = function(Vue) {Vue.directive('hasPermi', hasPermi)
}if (window.Vue) {window['hasPermi'] = hasPermiVue.use(install);
}export default install
?3.使用自定義指令
數組里面的數字的接口獲取的,和后端規定好,數字幾代表什么權限,比如我和后端規定好,4代碼頁面權限=
<div class="living-room-list-rep" v-hasPermi="['4']">