element table跨分頁多選及回顯的實現(xiàn)示例
1.data中定義getRowKeys,記錄每行的key值
getRowKeys(row) { ? ?return row.id; },
2.el-table綁定getRowKeys
<el-table ? ? :data="tableData" ? ? @selection-change="handleSelectionChange" ? ? :row-key="getRowKeys" >
3.將selection列的reserve-selection設(shè)為true
<el-table-column ? ? type="selection" ? ? width="50" ? ? align="center" ? ? :reserve-selection="true" ></el-table-column>
4.表格數(shù)據(jù)選中方法handleSelectionChange
handleSelectionChange(rows) { ? ? this.multipleSelection = rows; ? ? this.select_number = this.multipleSelection.length; ? ? this.select_Id = []; ? ? if (rows) { ? ? ? ? rows.forEach((row) => { ? ? ? ? ? if (row) { ? ? ? ? ? ? this.select_Id.push(row.id); ? ? ? ? ? } ? ? ? ? }); ? ? } },
代碼整理
<template> ? <div> ? ? <el-table @selection-change="handleSelectionChange" :row-key="getRowKeys"> ? ? ? <el-table-column type="selection" width="50" align="center" :reserve-selection="true">? ? ? ? </el-table-column> ? ? </el-table> ? ? <el-pagination>...</el-pagination> ? </div> </template> <script> export default { ? data() { ? ? return { ? ? ? multipleSelection: [], // 表格選中 ? ? ? getRowKeys(row) {//記錄每行的key值 ? ? ? ? return row.id; ? ? ? }, ? ? ? select_number: "", //表格select選中的條數(shù) ? ? ? select_Id: [], //表格select復(fù)選框選中的id ? ? } ? }, ? methods: { ? ? handleSelectionChange(rows) { ? ? ? this.multipleSelection = rows; ? ? ? this.select_number = this.multipleSelection.length; ? ? ? this.select_Id = []; ? ? ? if (rows) { ? ? ? ? rows.forEach((row) => { ? ? ? ? ? if (row) { ? ? ? ? ? ? this.select_Id.push(row.id); ? ? ? ? ? } ? ? ? ? }); ? ? ? } ? ? }, ? } }
到此這篇關(guān)于element table跨分頁多選及回顯的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)element table跨分頁多選及回顯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue學(xué)習(xí)教程之帶你一步步詳細(xì)解析vue-cli
這篇文章的主題是vue-cli的理解?;蛟S,很多人在開發(fā)vue的時候,我們會發(fā)現(xiàn)一個問題——只會去用,而不明白它的里面的東西?,F(xiàn)在的框架可以說是足夠的優(yōu)秀,讓開發(fā)者不用為搭建開發(fā)環(huán)境而煩惱。但是有時候,我們還是得回到原始生活體驗一下,才能夠讓自己更上層樓。2017-12-12Vue + iView實現(xiàn)Excel上傳功能的完整代碼
前一段時間項目經(jīng)歷了前端上傳文件的過程,首先進(jìn)入頁面會展示默認(rèn)的樣子,選中要上傳的excel文件,本文通過實例圖文相結(jié)合給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-06-06