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,
        }
        ]
相关推荐
执行上下文7 小时前
WordPress评论留言通知推送插件!
javascript·php
源码获取_wx:Fegn08957 小时前
基于springboot + vue考勤管理系统
java·开发语言·vue.js·spring boot·后端·spring·课程设计
m0_471199637 小时前
【vue】diff算法简介
前端·vue.js·算法
冬男zdn8 小时前
Vue 3 从基础到高阶全攻略
前端·javascript·vue.js
郑州光合科技余经理8 小时前
定制开发实战:海外版外卖系统PHP全栈解决方案
java·服务器·开发语言·javascript·git·uni-app·php
冬男zdn8 小时前
前端可视化图表库精选与实战指南
前端·javascript
局外人LZ8 小时前
前端二维码技术全景:从原生JS到Vue/React/Uniapp/小程序的二维码生成
前端·javascript
m0_471199638 小时前
【场景】笛卡尔积
开发语言·前端·javascript
顾安r8 小时前
12.15 脚本网页 bash内建命令
java·前端·javascript·html·bash