elementUI table二次封裝

1.HTMLjavascript

<template>
  <el-table
      ref="table"
      element-loading-text="Loading"
      :data="tableData"
      border 
      tooltip-effect="dark"
      style="width:100%">
      <el-table-column v-for="(item,index) in tableLabel" :width="item.width ? item.width : ''" :key="index" :align="item.align" :label="item.label" :prop="item.param" :sortable="item.sortable ? 'custom' : false">
        <template slot-scope="scope">
          <span v-if="item.render">
            {{item.render(scope.row)}}
          </span>
          <span v-else>{{scope.row[item.param]}}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="tableOption.label" :width="tableOption.width" :label="tableOption.label" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button  v-for="(item,index) in tableOption.options" :key="index" :type="item.type" :icon="item.icon" @click="handleButton(item.methods,scope.row,scope.row)" size="mini">
            {{item.label}}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
</template>

  2.子組件中jshtml

<script>
export default {
  props:{
    tableData:{
      type:Array,
      default: () => {
        return []
      }
    },
    tableLabel:{
      type:Array,
      default: () => {
        return []
      }
    },
    tableOption:{
      type:Object,
      default: () => {
        return {}
      }
    }
  },
  components:{},
  methods: {

  }
}
</script>

  3.父組件調用java

<table-cmp
      :table-data="tableData"
      :table-label="tableLabel"
      :table-option="tableOption"
    ></table-cmp>

  4.父組件jsspa

tableData:[],
tableLabel: [
        { label: '用戶名', param: 'usr', align: 'center',sortable:true },
        { label: '公司名稱', param: 'company', align: 'center' },
        { label: '辦公郵箱', param: 'email', align: 'center',width:'200' },
        { label: '註冊時間', param: 'registTime', align: 'center',sortable:true },
        { label: '審覈狀態', param: 'status', align: 'center',sortable:true, render:  (row) => {
            if (row.status === 0) {
              return '未審覈'
            } else if (row.status === 1) {
              return '審覈經過'
            } else if(row.status ===2) {
              return '審覈不經過'
            } else {
              return '禁用'
            }
          }        
        }
      ],
      tableOption: {
        label: '操做',
        width: '200',
        options: [
          { label: '預覽', type: 'primary', icon: 'el-icon-view', methods: 'preview' },
          { label: '審覈', type: 'primary', icon: 'el-icon-upload2', methods: 'audit' },
        ]
      }

  二次封裝,將全部的信息動態生成。component

相關文章
相關標籤/搜索