vue3封装el-table

本文介绍了如何在Vue.js应用中使用ElementUI的el-table组件创建可定制的表格,包括列配置、多选功能和操作栏的实现,以及数据绑定和事件处理。
摘要由CSDN通过智能技术生成

<template>

  <!-- tableData:  接口获取的列表值

        tableDateList:{

                      prop:  label的key值

                      label:  表格的lable值

                      width:  表格的宽度

                      idFormatter: 表格自定义方法,可用来转译字段  例如:idFormatter (row){row.sex==0?男:女}

                      align:   文字对齐方式

                      operate :是否显示操作栏按钮

                      buttonList:[{

                            text:   按钮中文名称

                      }  ]        

        }

        handleSelectionChange(选中行数据):    多选时传递给父组件获取选中项

        handleClick(点击行数据,点击按钮名称)    点击操作栏传给父组件数据

        slotIndex:    是否显示序号

        isSelection:  是否显示多选

    -->

  <el-table

    border

    :data="tableData"

    style="width: 100%; height: calc(100vh - 420px)"

    @selection-change="handleSelectionChange"

  >

    <el-table-column v-if="isSelection" type="selection" width="55" />

    <el-table-column v-if="slotIndex" type="index" label="序号" width="150" />

    <el-table-column

      v-for="item in tableDateList"

      :key="item.prop"

      :prop="item.prop"

      :label="item.label"

      :width="item.width"

      :formatter="item.idFormatter"

      :align="item.align"

      show-overflow-tooltip

    >

      <template #default="scope" v-if="item.operate">

        <el-button

          link

          type="primary"

          v-for="items in item.buttonList"

          :key="items.text"

          size="small"

          @click="handleClick(scope, items.text)"

          >{{ items.text }}</el-button

        >

      </template>

    </el-table-column>

  </el-table>

</template>

<script  setup>

import { ref, defineProps, onMounted, toRaw, computed, watch } from "vue";

const emit = defineEmits(["doSth"]);

onMounted(() => {

  console.log(props.tableDateList);

});

const props = defineProps({

  tableDateList: [],

  tableData: [],

  slotIndex: false,

  isSelection: false,

  handleSelectionChange: {

    type: Function,

    default: () => {},

  },

  handleClick: {

    type: Function,

    default: () => {},

  },

});

const tableDatas = computed(() => {

  // const list =toRaw(props)

  return props.tableData;

});

</script>

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值