vue+element实现批量删除功能
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
今年开始学习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>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)