RuoYi | v-if 和 v-hasPermi冲突问题,隐藏el-table-column

需求:根据权限和条件隐藏el-table-column

原代码:

会发生冲突,隐藏不了,试将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
  }
}
import { checkRole, checkPermi } from '../../utils/permission';
export default {
  methods: {
    checkPermi,
  }
}

你可能感兴趣的:(vue.js,javascript,前端)