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

1.當寫后臺管理頁面時,使用element ui里的table表格時,表格中有操作按鈕,獲取當前行的數(shù)據(jù)時,我們可以使用 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)
},打印可得當前行數(shù)據(jù),你就可以處理這些數(shù)據(jù)了

2.但如果要實現(xiàn)的功能是在表頭上了,例如圖里的批量審核,那要怎么獲取當前前勾選的這一行的數(shù)據(jù)呢?這時我們可以用表格中提供的@selection-change="handleSelectionChange" 的multipleSelection來實現(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="作品價格" align="center" min-width="160">
</el-table-column>
</el-table>
</template> data(){
return {
multipleSelection:[]
}
}
//獲取所有選擇的項
handleSelectionChange(val) {
console.log(val)
this.multipleSelection = val;
},打印可得當前行數(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("請選擇要審核的作品", "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 為選擇了多少項。
拿當前選中的行的數(shù)據(jù),進行傳值,實現(xiàn)批量審核功能。
ps:Vue element怎么獲取table表格當前行數(shù)據(jù)和索引值
怎么拿表格當前行數(shù)據(jù)平時我們在使用表格時通過template的slot-scope="scope",使用scope.row拿到當前行的數(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>怎么拿表格當前行索引值
<el-table max-height="290" :data="userTableData" border style="width: 100%">
<el-table-column label="序號">
<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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3實現(xiàn)掛載全局方法和用getCurrentInstance代替this
這篇文章主要介紹了Vue3實現(xiàn)掛載全局方法和用getCurrentInstance代替this,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-04-04
VUE項目啟動沒有問題但代碼中script標簽有藍色波浪線標注
這篇文章主要給大家介紹了關(guān)于VUE項目啟動沒有問題但代碼中script標簽有藍色波浪線標注的相關(guān)資料,文中將遇到的問題以及解決的方法介紹的非常詳細,需要的朋友可以參考下2023-05-05
vuejs實現(xiàn)標簽選項卡動態(tài)更改css樣式的方法
這篇文章主要介紹了vuejs實現(xiàn)標簽選項卡-動態(tài)更改css樣式的方法,代碼分為html和js兩部分,需要的朋友可以參考下2018-05-05

