0
点赞
收藏
分享

微信扫一扫

【Vue】按钮权限

Soy丶sauce 2022-04-06 阅读 44
vue.js
// components/Home.vue

async getMenuList() {
      try {
        const { menuList, actionList } = await this.$api.getPermissionList();
        this.userMenu = menuList;
        this.$store.commit("saveUserMenu", menuList);
        this.$store.commit("saveUserAction", actionList);
      } catch (error) {
        console.error(error);
      }
    }
// main.js

// 按钮权限
app.directive('has', {
    beforeMount: (el, binding) => {
        // 获取按钮权限
        let actionList = storage.getItem('actionList')
        let value = binding.value
        // 判断列表中是否有对应按钮权限标识
        let hasPermission = actionList.includes(value)
        if (!hasPermission) {
            el.style = 'display:none;'
            // 添加一个宏任务
            setTimeout(() => {
                el.parentNode.removeChild(el)
            }, 0);
        }
    }
})
// views/User.vue

<el-button 
		@click="handleEdit(scope.row)"
    size="mini"
		v-has:add="'user-delete'"
>编辑</el-button>
<el-button
    type="danger"
    size="mini"
    @click="handleDel(scope.row)"
    v-has:add="'user-delete'"
>删除</el-button>
举报

相关推荐

0 条评论