需求:根据权限和条件隐藏el-table-column
原代码:
<el-table-column type="selection" width="55" align="center" reserve-selection v-if="istxChange === true" && v-hasPermi="['archives:archiveBak:back']" />
会发生冲突,隐藏不了,试将v-if改为v-show也无效。
解决方法:
使用checkPermi方法:
import store from '@/store'
/**
* 字符权限校验
* @param {Array} value 校验值
* @returns {Boolean}
*/
export function checkPermi(value) {
if (value && value instanceof Array && value.length > 0) {
const permissions = store.getters && store.getters.permissions
const permissionDatas = value
const all_permission = "*:*:*";
const hasPermission = permissions.some(permission => {
return all_permission === permission || permissionDatas.includes(permission)
})
if (!hasPermission) {
return false
}
return true
} else {
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
return false
}
}
<el-table-column type="selection" width="55" align="center" reserve-selection v-if="istxChange === true && checkPermi(['archives:archiveBak:back'])" />
import { checkRole, checkPermi } from '../../utils/permission';
export default {
methods: {
checkPermi,
}
}