今年開始學習vue+element實現后臺開發,在實現批量刪除功能時有2個小知識點記錄在下:
1、如何實現單擊行交替選中當前行的復選框,element官網的table實例中沒有找到?!ㄟ^row-click和toggleRowSelection實現
2、如何獲取選中行的值來實現批量刪除?!ㄟ^selection-change實現
代碼如下
html:
<div class="row mt30 pl15">
<el-button type="warning" @click="delGroup" :disabled="this.sels.length === 0">批量刪除</el-button><!--disabled值動態顯示,默認為true,當選中復選框后值為false-->
</div>
<el-table :data="tableList" :fit="true" @row-click="handleCurrentChange" @selection-change="selsChange" ref="table">
<el-table-column type="selection" width="55" reserve-selection=""></el-table-column>
<el-table-column prop="id" label="ID" width="150" class-name="bg_blue"></el-table-column>
<el-table-column prop="cpsProductId" label="商品ID" width="200"></el-table-column>
<el-table-column prop="productName" label="商品名稱" width="200" show-overflow-tooltip></el-table-column>
<el-table-column label="圖片" width="200">
<template scope="data1">
<img :src="data1.row.imgsrc" class="mt10 mb10">
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template scope="scope">
<el-button type="primary" size="small" @click="onEditSku(scope.row.id)">編輯</el-button>
<el-button size="small" @click="onDelProduct(scope.row.id)">刪除</el-button>
</template>
</el-table-column>
</el-table>
js:
<script>
export default {
name: 'product',
mounted() {
this.onSearch()
},
data() {
return {
sels: [],//選中的值顯示
tableList: [],
total: 0,
start: 0,
size: 10
}
},
methods: {
selsChange(sels) {
this.sels = sels
},
delGroup() {
var ids = this.sels.map(item => item.id).join()//獲取所有選中行的id組成的字符串,以逗號分隔
},
handleCurrentChange(row, event, column) {
this.$refs.table.toggleRowSelection(row)
}
}
}
</script>
以上這篇vue+element實現批量刪除功能的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。