注册全局组件:
directives.js
function permissionBtns(el, binding) { let data = binding.value.data, prop = binding.value.prop, val = binding.value.val; if (data[prop] == val) { el.style.display = "block"; } else { el.style.display = "none"; } } export { permissionBtns };
在main.js中注册
//全局自定义指令 import * as directives from "./js/directives/directives"; Object.keys(directives).forEach((key) => { Vue.directive(key, directives[key]); });
在页面中使用
v-permissionBtns: permissionBtns是注册的名称,
{data: row.data, prop: 'state', val: 2}是参数
<div v-permissionBtns="{ data: row.data, prop: 'state', val: 2 }"> 审核 </div>