日常记录#6参数表格

该段代码展示了一个Vue.js组件,用于创建带有动态列的表格。组件接受`tableData`和`propsArr`作为属性,分别用于表格数据和列定义。列定义可以包含类型、属性、标签、样式等信息,支持自定义渲染函数来处理单元格内容。当列定义或表格数据改变时,会自动调整表格布局。
摘要由CSDN通过智能技术生成
<template>
  <div class="table-wrap">
    <el-table ref="display-table" :data="tableData" border style="width: 100%; font-size: 12px;">
      <el-table-column v-for="(column, index) in propsArr" :key="index"
        :type="(column.type && ['index', 'selection', 'expand'].includes(column.type)) ? column.type : null"
        :prop="column.prop" :label="column.label"
        :show-overflow-tooltip="[true, false].includes(column.toolTip) ? column.toolTip : true"
        :align="column.align ? column.align : 'center'" :width="column.width ? column.width : 'auto'">
        <template v-if="!(column.type && ['index', 'selection', 'expand'].includes(column.type))" v-slot="scope">
          <span v-if="column.render" :style="column.style ? column.style : {}">
            {{ renderHtml(column, scope) }}
            <slot :name="'renderHtml'" />
          </span>
          <span v-else :style="column.style ? column.style : {}">{{ scope.row[column.prop] }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: 'TableDisplayProp',
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    propsArr: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
    }
  },
  watch: {
    propsArr: {
      handler() {
        this.$refs?.['display-table']?.doLayout()
      },
      deep: true
    },
    tableData(nv) {
    }
  },
  created() {
  },
  methods: {
    renderHtml(col, scope) {
      if (typeof col.render === 'function') {
        // 执行函数,动态生成VNode传入具名插槽renderHtml中
        this.$slots['renderHtml'] = col.render(this.$createElement, scope)
      }
      return null
    }
  }
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值