基于element UI Table的二次封装

1.封装的表格组件代码如下:

 

2.父组件对表格的使用例子

 3.封装的table组件代码

<template>
    <div>
  <el-table
  :data="tableData"
  style="width: 100%"
  :stripe="stripe"
  :border="border"
  :siez="size"
  :height="height"
  :max-height='maxHeight'
  :highlight-current-row="highlight"
  @selection-change="handleSelectChange"
  :header-cell-style="headerCellStyle"
  :cell-style="cellStyle"
  :row-key="rowKey"
  :tree-props="treeProps"
  :default-sort="defaultSort"
  @expand-change="handelExpandChange"
  @row-click="rowClick"
  @cell-click="cellClick"
  >
  <template v-for="(item,index) in tableColumn">
    <!-- type为slection或index -->
    <el-table-column 
      v-if="isTypeColumn(item)"
      v-bind="item"
      :key="item.prop"
    >
    </el-table-column>
    <!-- 插槽,自定义内容 当添加type:'expand'可以展开表格行 -->
    <el-table-column 
    v-else-if="item.slotMode"
    v-bind="item"
    :key="item.prop"
    >
      <template slot-scope="scope">
        <slot :name="item.prop" :scope="scope"></slot>
      </template>
    </el-table-column>
    <!-- 常规内容 -->
    <el-
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue基于Element UI Table二次封装可以通过创建一个自定义的组件来实现。以下是一个简单的示例,演示了如何封装一个基于Element UI Table组件: ```vue <template> <el-table :data="tableData" :row-key="rowKey" :height="height"> <!-- 渲染表头 --> <el-table-column v-for="column in columns" :key="column.prop" :prop="column.prop" :label="column.label"> <!-- 自定义插槽 --> <template slot-scope="scope"> <slot :column="column" :scope="scope"></slot> </template> </el-table-column> </el-table> </template> <script> export default { name: 'CustomTable', props: { tableData: { type: Array, required: true }, columns: { type: Array, required: true }, rowKey: { type: String, required: true }, height: { type: String, default: 'auto' } } } </script> ``` 在这个示例,我们创建了一个名为`CustomTable`的组件。它接受`tableData`、`columns`、`rowKey`和`height`作为props,分别表示表格数据、表格列配置、行数据的唯一标识以及表格的高度。 在模板,我们使用`el-table`和`el-table-column`来渲染Element UI的表格。我们使用了`v-for`指令来循环渲染表格列,并通过`slot-scope`来传递数据给插槽。插槽可以在父组件定义,并在插槽使用自定义的组件来渲染表格单元格内容。 通过这种方式,我们可以在父组件使用这个封装的自定义表格组件,并通过插槽来定制表格的内容和样式。 希望这个简单的示例能帮助到你进行Vue基于Element UI Table二次封装。如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值