vue elementui表格獲取某行數(shù)據(jù)(slot-scope和selection-change方法使用)
效果圖:
1.當(dāng)寫后臺(tái)管理頁(yè)面時(shí),使用element ui里的table表格時(shí),表格中有操作按鈕,獲取當(dāng)前行的數(shù)據(jù)時(shí),我們可以使用 slot-scope="scope"來獲取。
<el-table-column label="操作" align="center" prop="auditStatus" width="180" fixed="right"> <template slot-scope="scope"> <el-button type="text" size="large" @click="audit(scope.row)">審核</el-button> </template> </el-table-column>
audit(row){ console.log(row) },
打印可得當(dāng)前行數(shù)據(jù),你就可以處理這些數(shù)據(jù)了
2.但如果要實(shí)現(xiàn)的功能是在表頭上了,例如圖里的批量審核,那要怎么獲取當(dāng)前前勾選的這一行的數(shù)據(jù)呢?這時(shí)我們可以用表格中提供的@selection-change="handleSelectionChange" 的multipleSelection來實(shí)現(xiàn)。
<template> <el-table ref="multipleTable" :data="tableData3" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55"> </el-table-column> <el-table-column prop="title" label="作品名稱" align="center" width="160"> </el-table-column> <el-table-column prop="count" label="作品數(shù)量" align="center" min-width="160"> </el-table-column> <el-table-column prop="price" label="作品價(jià)格" align="center" min-width="160"> </el-table-column> </el-table> </template>
data(){ return { multipleSelection:[] } } //獲取所有選擇的項(xiàng) handleSelectionChange(val) { console.log(val) this.multipleSelection = val; },
打印可得當(dāng)前行數(shù)據(jù),你就可以處理這些數(shù)據(jù)了
例如:
<el-form-item> <el-button type="primary" @click="batchTransferTip()">批量審核</el-button> </el-form-item>
//批量審核 batchTransferTip() { if (this.multipleSelection.length == 0) { this.common.messageTip("請(qǐng)選擇要審核的作品", "error"); return false; } else { this.editboxName = "verify"; let planIdList = []; //遍歷數(shù)據(jù) for (let item of this.multipleSelection) { planIdList.push(item.id); } this.propData.id = planIdList; } },
注意:this.multipleSelection.length 為選擇了多少項(xiàng)。
拿當(dāng)前選中的行的數(shù)據(jù),進(jìn)行傳值,實(shí)現(xiàn)批量審核功能。
ps:Vue element怎么獲取table表格當(dāng)前行數(shù)據(jù)和索引值
怎么拿表格當(dāng)前行數(shù)據(jù)平時(shí)我們?cè)谑褂帽砀駮r(shí)通過template的slot-scope="scope",使用scope.row拿到當(dāng)前行的數(shù)據(jù)
<el-table max-height="290" :data="userTableData" border style="width: 100%"> <el-table-column label="名字"> <template slot-scope="scope"> {{scope.row.name}} </template> </el-table-column> <el-table-column label="年齡"> <template slot-scope="{row}"> {{row.age}} </template> </el-table-column> </el-table>
怎么拿表格當(dāng)前行索引值
<el-table max-height="290" :data="userTableData" border style="width: 100%"> <el-table-column label="序號(hào)"> <template slot-scope="scope"> {{scope.$index+1}} </template> </el-table-column> </el-table>
到此這篇關(guān)于vue elementui表格獲取某行數(shù)據(jù)(slot-scope和selection-change方法使用)的文章就介紹到這了,更多相關(guān)vue elementui表格獲取某行數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue(element ui)el-table樹形表格展示以及數(shù)據(jù)對(duì)齊方式
- vue?element?ui表格相同數(shù)據(jù)合并單元格效果實(shí)例
- vue+elementUI顯示表格指定列合計(jì)數(shù)據(jù)方式
- 使用vue+element?ui實(shí)現(xiàn)走馬燈切換預(yù)覽表格數(shù)據(jù)
- Vue組件庫(kù)ElementUI實(shí)現(xiàn)表格加載樹形數(shù)據(jù)教程
- vue elementUI table表格數(shù)據(jù) 滾動(dòng)懶加載的實(shí)現(xiàn)方法
- vue Element UI 解決表格數(shù)據(jù)不更新問題及解決方案
相關(guān)文章
Vue實(shí)現(xiàn)一個(gè)無限加載列表功能
這篇文章主要介紹了Vue實(shí)現(xiàn)一個(gè)無限加載列表功能,需要的朋友可以參考下2018-11-11Vue3.0?axios跨域請(qǐng)求代理服務(wù)器配置方式
這篇文章主要介紹了Vue3.0?axios跨域請(qǐng)求代理服務(wù)器配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04WebStorm無法正確識(shí)別Vue3組合式API的解決方案
這篇文章主要介紹了WebStorm無法正確識(shí)別Vue3組合式API的解決方案,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下2021-02-02Vue使用Element折疊面板Collapse如何設(shè)置默認(rèn)全部展開
這篇文章主要介紹了Vue使用Element折疊面板Collapse如何設(shè)置默認(rèn)全部展開,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01v-for中動(dòng)態(tài)校驗(yàn)el-form表單項(xiàng)的實(shí)踐
在項(xiàng)目開發(fā)中,我們經(jīng)常會(huì)遇到表單保存的功能,本文主要介紹了v-for中動(dòng)態(tài)校驗(yàn)el-form表單項(xiàng)的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧<BR>2022-05-05VUE使用docxtemplater導(dǎo)出word文檔實(shí)例(帶圖片)
docxtemplate支持的功能很多,語法包含變量替換、條件判斷、循環(huán)、列表循環(huán)、表格循環(huán)等,下面這篇文章主要給大家介紹了關(guān)于VUE使用docxtemplater導(dǎo)出word功能(帶圖片)的相關(guān)資料,需要的朋友可以參考下2023-06-06