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,
        }
        ]
相关推荐
Irene19917 分钟前
Vue3 规范推荐的 <script setup> 中书写顺序(附:如何响应路由参数变化)
vue.js·路由
pusheng202511 分钟前
普晟传感2026年新春年会总结与分析
前端·javascript·html
谢尔登12 分钟前
React19事件调度的设计思路
前端·javascript·react.js
2301_7965125231 分钟前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Lazyload 懒加载(懒加载的图片)
前端·javascript·react native·react.js·ecmascript·harmonyos
敲敲了个代码36 分钟前
从N倍人力到1次修改:Vite Plugin Modular 如何拯救多产品前端维护困境
前端·javascript·面试·职场和发展·typescript·vite
摘星编程40 分钟前
OpenHarmony环境下React Native:Timeline时间轴组件
javascript·react native·react.js
摘星编程42 分钟前
在OpenHarmony上用React Native:Timeline水平时间轴
javascript·react native·react.js
bigdata-rookie1 小时前
Starrocks 数据模型
java·前端·javascript
web打印社区1 小时前
前端实现浏览器预览打印:从原生方案到专业工具
前端·javascript·vue.js·electron
yuezhilangniao1 小时前
# 告别乱码:用FastAPI特性与Next.js打造类型安全的API通信
javascript·安全·fastapi