在寫項目中,發(fā)現(xiàn)v-hasPermi只能隱藏按鈕,像一些標簽是不能隱藏的,比如說el-table中的el-table-column
如下圖所示:

image.png
有兩種方法:
方法一
要想進行標簽的權限隱藏,可以配合v-if進行
this.$auth.hasPermi('production:semi:registeExport')
//既然拿到了判斷權限的標識鑰匙,那接下來就好辦了
<el-table-column
label="操作"
align="center"
//直接在標簽上使用v-if來進行判斷是否開啟權限,即可實現(xiàn)標簽的權限隱藏
v-if="$auth.hasPermi('production:semi:registeExport')"
width="200"
>
</el-table-column>
總結:關鍵 this.$auth.hasPermi('production:semi:registeExport') 這行代碼可以判斷是否是開啟權限,再配合v-if進行標簽的權限隱藏即可。
方法二
拿到設置的所有權限,根據(jù)字段去判斷是否包含其中
// 獲取權限
hasPermi(permission) {
let userPermissions = this.$store.getters.permissions
return userPermissions.includes(permission) || userPermissions.includes('*:*:*');
},
<el-table-column
label="操作"
align="center"
width="120"
class-name="small-padding fixed-width"
fixed="right"
v-if="hasPermi('production:semi:registeExport')"
>
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
v-hasPermi="['production:semi:registeExport']"
@click="handleUpdate(scope.row)"
>修改xxx
</el-button>
</template>
</el-table-column>