自己将elementui中的el-table封装成的table,减少template中的代码

本文介绍了如何将ElementUI的el-table组件进行封装,以减少模板中的代码量。主要功能包括:状态转换过滤器,表格内编辑功能,多行单元格内容对齐,以及操作列动态按钮名称变更。示例代码展示了封装后的组件使用方法和数据结构。
摘要由CSDN通过智能技术生成

代码写的有点low,但能用。
使用场景
1.Status:后台传的数字转化成其他内容,类似过滤器
2.操作中点击修改按钮,表格span变成input,不过得这样加属性,类似双向绑定的原理,能立刻变
this.AbnormaOrderList = list.map(item => {
this.$set(item, ‘AbnormaOrderBoolean’, true)
return item

3.一个表格单元格有几行排齐的内容
4.再2的操作基础上,有时要按钮名字变,修改变成确定后,导致每行都变,也封装了只变操作那行的名字,不过会麻烦点,就是btn写成[[]]的形式,具体不说了

template:
<ElTables
v-loading=“listLoading”
:columns=“see_columns”
:data=“seeList”
@handleBtnClick=“handleBtnClick”
/>

data:
see_columns: [
{ name: ‘序号’, type: ‘index’, tooltip: true, width: ‘50’ },
{ name: ‘产品名称’, desc: ‘ItemName’, tooltip: true },
{ name: ‘单价’, desc: ‘OrderPrice’, tooltip: true },
{ name: ‘批次信息’, first: ‘LotCode’, second: ‘ManufactureDt’, third: ‘DisabledDatetime’, fourth: ‘ApprovalNum’, fifth: ‘SterilizationLotMaster’, sixth: ‘Serial’, many: true, tooltip: true },
{ name: ‘是否扫码’, desc: ‘barcodeflag’, tooltip: true, show: true, status: [‘主条码(否)批次条码(否)’, ‘主条码(是)批次条码(否)’, ‘主条码(是)批次条码(是)’] },
{ name: ‘操作’, desc: ‘operate’, width: ‘240’,
btns: [
{ name: ‘编辑’, btnType: ‘success’, clickType: ‘editProductLineUser’ },
{ name: ‘修改’, btnType: ‘success’, clickType: ‘addProductLineUser’ },
{ name: ‘删除’, btnType: ‘success’, clickType: ‘deleteProductLineUser’ }
]
}
],

script
import ElTable from '@/components/table’导入封装的组件
按钮事件
/** 表格内点击方法 */
handleBtnClick(scope) {
if (scope.type === ‘addProductLineUser’) {
} else if (scope.type === ‘editProductLineUser’) {
} else if (scope.type === ‘deleteProductLineUser’) {
}

<template>
  <div>
    <el-table
      ref="multipleTable"
      :data="formatData"
      border
      stripe
      style="width: 100%"
      @select="onTableSelect"
      @selection-change="handleSelectionChange"
    >
      >
      <!-- 表头 、表体-->
      <template v-for="column in columns">
        <!-- 循环父页面数据、对数据进行判断参数处理-->
        <el-table-column
          v-if="column.type"
          :fixed="column.fixed"
          :key="column.desc"
          :label="column.name"
          :sortable="column.sortable?'custom':false"
          :type="column.type"
          :width="column.width==undefined?'auto':column.width"
          align="center"
        />
        <el-table-column
          v-if="!column.type"
          :fixed="column.fixed"
          :key="column.desc"
          :label="column.name"
          :prop="column.desc"
          :show-overflow-tooltip="column.tooltip?true:false"
          :sortable="column.sortable?'custom':false"
          :width="column.width==undefined?'auto':column.width"
          align="center"
        >
          <template slot-scope="scope">
            <!-- column.link为true  显示可点击状态 -->
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值