基于Element中table实现多行复选并自定义标题

如上图后三列同时需要修改表格标题,之前的type=“selection"无法满足当前需求,查了一下官方文档,提供了一个render-header函数,直接用jsx语法就好。

<template>
    <div>
        <el-table :data="tableData" border stripe>
            <el-table-column
              prop="name"
              label="字段"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="type"
              label="类型"
              align="center"
            ></el-table-column>
            <el-table-column :render-header="renderColumnHeader1">
              <template slot
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
VueElement UI的Table组件实现分页复选功能,可以按照以下步骤进行操作: 1. 在Vue组件引入Element UI的Table和Checkbox组件: ```javascript import { Table, Checkbox } from 'element-ui'; ``` 2. 在data定义需要用到的变量: ```javascript data() { return { // 表格数据 tableData: [], // 选的行数据 selectedRows: [], // 是否全选 isAllSelected: false } } ``` 3. 在模板使用Table和Checkbox组件,并设置相应属性和事件: ```html <template> <div> <el-table :data="tableData" @row-click="handleRowClick"> <el-table-column type="selection" width="55"> <template slot-scope="scope"> <el-checkbox v-model="selectedRows" :label="scope.row" @change="handleCheckboxChange"></el-checkbox> </template> </el-table-column> <!-- 其他列定义--> </el-table> </div> </template> ``` 4. 在methods定义事件处理函数: ```javascript methods: { // 单击行选/取消选 handleRowClick(row) { const index = this.selectedRows.indexOf(row); if (index > -1) { this.selectedRows.splice(index, 1); } else { this.selectedRows.push(row); } }, // 全选/取消全选 handleCheckboxChange(value) { if (value.length === this.tableData.length) { this.isAllSelected = true; } else { this.isAllSelected = false; } } } ``` 5. 在模板使用全选Checkbox,并绑定isAllSelected属性: ```html <el-checkbox v-model="isAllSelected" @change="handleSelectAllChange">全选</el-checkbox> ``` 6. 在methods定义全选Checkbox的 change 事件: ```javascript methods: { // 全选/取消全选 handleSelectAllChange(value) { if (value) { this.selectedRows = [...this.tableData]; } else { this.selectedRows = []; } } } ``` 以上就是在VueElement UI的Table实现分页复选功能的步骤。通过监听行点击事件,可以实现点击行选/取消选的功能;通过绑定Checkbox的v-model和change事件,可以实现全选功能;通过管理选的行数据,可以获取用户选择的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码研究员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值