elementPlus tables表格的二次封装

文章介绍了如何在Vue项目中使用ElementUI的el-table组件,包括自定义列配置、动态渲染和处理多层级属性的选择。
摘要由CSDN通过智能技术生成
<el-table :data="tableData" :max-height="maxHeight"  :min-height="minHeight"  @select="handleSelect" @select-all="handleSelectAll">
	<el-table-column v-if="isCheck" type="selection" width="55" align="center" ></el-table-column>
	<el-table-column :prop="item.prop" :label="item.label" v-for="item in columnData" :key="item.id" :width="item.width"
      :fixed="item.fixed" align="center" >
      <template v-slot="{ row }">
        <slot :name="item.prop" :row="row" v-if="!item.visable" >
          {{ getProp(row, item) }}
        </slot>
      </template>
    </el-table-column>
    <template v-slot:empty>
      <el-empty description="暂无数据"></el-empty>
    </template>
</el-table>

export default {
  name: "Tables",
  props: {
    tableData: {
      type: Array,
      default: [],
    },
    columnData: {
      type: Array,
    },
    tableLoading: {
      type: Boolean,
      default() {
        return false;
      },
    },
    isCheck: {
      type: Boolean,
      default() {
        return false;
      },
    },
    handleSelect: {
      type: Function,
    },
    handleSelectAll: {
      type: Function,
    },
    isStripe: {
      type: Boolean,
      default() {
        return false;
      },
    },
    maxHeight: {
      type: String
    },
    minHeight: {
      type: String
    },
    height: {
      type: String
    }
  },
  data() {
    return {};
  },
  methods: {
    // 处理传递的属性名是xxx[x].xxx (只能链选一层)
    getProp(row, item) {
      let reg = /^(.+)\[(\d+)\]\.?(.*)$/;
      let matched = item.prop.match(reg);
      if (matched) {
        let arr = row[matched[1]];
        let prop = arr[matched[2]];
        let prop2 = prop[matched[3]];
        return prop2;
      }
      return row[item.prop];
    },
  },
 
};
</script>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值