在mian.ts中
app.directive('has-accountCategory', {
mounted(el, binding) {
//传值打印
console.log(binding.value);
//获取权限
const accountCategory = JSON.parse(sessionStorage.getItem('userInfo')).accountCategory
//权限判断
if (accountCategory != 2) {
el.style.display = 'none'; // 如果没有权限,隐藏按钮
}
},
//更新页面使用 没用到不知道啥意思
// updated(el, binding) {
// this.componentUpdated(el, binding); // 当权限变化时重新评估
// }
});
页面使用
<el-button v-has-accountCategory link type="primary">
编辑
</el-button>
//或者直接传值判断
<el-button v-has-accountCategory='1' link type="primary">
编辑
</el-button>
文章介绍了如何在Angular应用中使用自定义指令(has-accountCategory)来控制按钮显示,根据用户存储的accountCategory权限判断是否显示‘编辑’按钮。如果账户类别不是2,按钮将被隐藏。
992

被折叠的 条评论
为什么被折叠?



