vue elementui表格獲取某行數(shù)據(jù)(slot-scope和selection-change方法使用)
效果圖:

1.當(dāng)寫后臺(tái)管理頁面時(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組件庫ElementUI實(shí)現(xiàn)表格加載樹形數(shù)據(jù)教程
- vue elementUI table表格數(shù)據(jù) 滾動(dòng)懶加載的實(shí)現(xiàn)方法
- vue Element UI 解決表格數(shù)據(jù)不更新問題及解決方案
相關(guān)文章
vue中@click綁定事件點(diǎn)擊不生效的原因及解決方案
根據(jù)Vue2.0官方文檔關(guān)于父子組件通訊的原則,父組件通過prop傳遞數(shù)據(jù)給子組件,子組件觸發(fā)事件給父組件,這篇文章主要介紹了vue中@click綁定事件點(diǎn)擊不生效的解決方案,需要的朋友可以參考下2022-12-12
npm run dev報(bào)錯(cuò)信息及解決方法
這篇文章主要為大家介紹了npm run dev報(bào)錯(cuò)信息及解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09
Vue3實(shí)現(xiàn)掛載全局方法和用getCurrentInstance代替this
這篇文章主要介紹了Vue3實(shí)現(xiàn)掛載全局方法和用getCurrentInstance代替this,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
VUE項(xiàng)目啟動(dòng)沒有問題但代碼中script標(biāo)簽有藍(lán)色波浪線標(biāo)注
這篇文章主要給大家介紹了關(guān)于VUE項(xiàng)目啟動(dòng)沒有問題但代碼中script標(biāo)簽有藍(lán)色波浪線標(biāo)注的相關(guān)資料,文中將遇到的問題以及解決的方法介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05
vuejs實(shí)現(xiàn)標(biāo)簽選項(xiàng)卡動(dòng)態(tài)更改css樣式的方法
這篇文章主要介紹了vuejs實(shí)現(xiàn)標(biāo)簽選項(xiàng)卡-動(dòng)態(tài)更改css樣式的方法,代碼分為html和js兩部分,需要的朋友可以參考下2018-05-05

