Vue中directives的用法

2021-09-18  本文已影响0人  艾希_可可

import Vue from 'vue'
/权限指令/
const has = Vue.directive('has', {
bind: function (el, binding, vnode) {
// 获取按钮权限
let btnPermissions = vnode.context.route.meta.btnPermissions.split(","); if (!Vue.prototype._has(btnPermissions)) {
el.parentNode.removeChild(el);
}
}
});
// 权限检查方法
Vue.prototype.$_has = function (value) {
let isExist = false;
let btnPermissionsStr = sessionStorage.getItem("btnPermissions");
if (btnPermissionsStr == undefined || btnPermissionsStr == null) {
return false;
}
if (value.indexOf(btnPermissionsStr) > -1) {
isExist = true;
}
return isExist;
};
export {has}
/然后在main.js文件引入文件/
import has from './public/js/btnPermissions.js';

/页面中按钮只需加v-has即可/
<el-button @click='editClick' type="primary" v-has>编辑</el-button>

原文链接:https://blog.csdn.net/qq_31837621/article/details/80819126

参考来自
https://blog.csdn.net/qq_31837621/article/details/80819126?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control

上一篇 下一篇

猜你喜欢

热点阅读