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,
        }
        ]
相关推荐
Hi_kenyon6 小时前
VUE3套用组件库快速开发(以Element Plus为例)二
开发语言·前端·javascript·vue.js
Irene19916 小时前
Vue 3 响应式系统类型关系总结(附:computed、props)
vue.js·props·响应式类型
起名时在学Aiifox6 小时前
Vue 3 响应式缓存策略:从页面状态追踪到智能数据管理
前端·vue.js·缓存
天若有情6736 小时前
校园二手交易系统实战开发全记录(vue+SpringBoot+MySQL)
vue.js·spring boot·mysql
计算机程序设计小李同学7 小时前
个人数据管理系统
java·vue.js·spring boot·后端·web安全
EndingCoder7 小时前
Any、Unknown 和 Void:特殊类型的用法
前端·javascript·typescript
JosieBook8 小时前
【Vue】09 Vue技术——JavaScript 数据代理的实现与应用
前端·javascript·vue.js
Eason_Lou8 小时前
webstorm开发vue项目快捷跳转到vue文件
ide·vue.js·webstorm
起名时在学Aiifox8 小时前
前端文件下载功能深度解析:从基础实现到企业级方案
前端·vue.js·typescript
云上凯歌9 小时前
01 ruoyi-vue-pro框架架构剖析
前端·vue.js·架构