Eltable二次封装

封装

html 复制代码
<template>
    <div>
    <el-table
      :data="tableData"
      border
      stripe
      :header-row-style="{
        background: '#F1F6FF !important',
        color: '#3E445',
        fontWeight: '500',
      }"
    >
      <template v-for="(item, index) in column" >
        <el-table-column
            v-if="item.slot"
            :align="item.align"
            :label="item.label"
            :min-width="item.minWidth"
            :width="item.width"
            :fixed="item.fixed"
        >
          <template slot-scope="scope">
              <slot :name="item.slot" :row="scope.row"></slot>
          </template>
        </el-table-column>
        <el-table-column
            v-else
            :align="item.align"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :min-width="item.minWidth"
        ></el-table-column>
      </template>
    </el-table>
    <el-pagination
      v-if="total"
      background
      layout="total, sizes, prev, pager, next"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      :current-page="currentPage"
      :total="total"
      class="fyDiv"
      @size-change="handleSize"
      @current-change="handlePage"
    ></el-pagination>
    </div>
</template>

<script>
export default {
  props: {
    tableData: {
        type: Array,
        default: () => []
    },
    column: {
        type: Array,
        default: () => []
    },
    total: {
        type: Number,
        default: () => 0
    },
    pageSizes: {
        type: Array,
        default: () => [10, 20, 30, 40],
    },
    pageSize: {
        type: Number,
        default: () => 10
    },
    currentPage: {
        type: Number,
        default: () => 1
    },
  },
  data() {
    return {
        
    }
  },
  methods: {
    handleSize(){
      this.$emit('handleSize')
    },
    handlePage(){
      this.$emit('handlePage')
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__cell{
    min-height: 46px;
}
</style>

使用

html 复制代码
  <TablePage
            :column="column"
            :tableData="customerTable"
            >
               
                <template #level="scope">
                    {{ scope.row.level | CustomerLevelType }}
                </template>
                <template #stage="scope">
                    {{ scope.row.stage | CustomerStageType }}
                </template>
                <template #type="scope">
                    {{ scope.row.type | CustomerStageType }}
                </template>
                <template #action="scope">
                    <el-link type="primary" :underline="false" 
                    @click="openCustomer('edit',scope.row)" style="">按钮</el-link>
                    <el-link type="primary" :underline="false"
                    @click="openDetails(scope.row.id)">按钮</el-link>
                </template>
            </TablePage>

数据格式

html 复制代码
 column: [
            {
            label: '客户ID',
            prop: 'number',
            minWidth: 150,
            },{
            label: '客户名称',
            slot: 'name',
            minWidth: 180,
            },{
                label: '客户级别',
            prop: 'levelStr',
            minWidth: 100,
            },{
                label: 'POI名称',
            slot: 'poiName',
            minWidth: 150,
        }
        ]
相关推荐
程序员小寒1 分钟前
JavaScript设计模式(一):单例模式实现与应用
javascript·单例模式·设计模式
Dxy12393102166 分钟前
JS如何把数据添加到列表中
前端·javascript·vue.js
御形封灵7 分钟前
基于canvas的路网编辑交互
开发语言·javascript·交互
m0_5027249510 分钟前
Arco design vue 阻止弹窗关闭
javascript·vue.js·arco design
蜡台10 分钟前
Uniapp 实现 二手车价格评估 功能
前端·javascript·uni-app·估值·汽车抵押·二手车评估
Yan-英杰12 分钟前
TypeScript+React 全栈生态实战:从架构选型到工程落地,告别开发踩坑
javascript·学习·typescript
海天鹰14 分钟前
JSZip库读取ePub电子书目录
javascript
比特森林探险记20 分钟前
Element Plus 实战指南
前端·javascript
嘉琪00129 分钟前
Day8 完整学习包(Vue 基础 & 响应式)——2026 0320
前端·vue.js·学习
FlyWIHTSKY30 分钟前
Vue3 单文件中不同的组件
前端·javascript·vue.js