同问
@ECHOyougf 我是这样处理的
在template 里面
<mt-cell-swipe
:id="i.labelId"
class="label_cells_swipe"
:right="[
{
content: '删除',
style: { background: 'red', color: '#fff' },
handler: () => labelDel(i.labelId)
}
]">
在rightbutton里面加id
然后在methods里面写上删除的办法
// 删除标签
labelDel(id) {
for (var i = 0; i < this.all_label.length; i++) {
if (this.all_label[i].labelId == id) {
this.all_label.splice(i, 1);
break;
}
}
this.delLabel(id)
}
@hopkinson thanks ! !
参考您的做法,我用了组件提供的value,拿到了数据!
<mt-cell-swipe v-for="n in 10"
:right="[{ content: '删除', style: {background: 'red', color: '#fff', marginLeft: '2px'},
handler: () => deleteCell(n)}]"
icon="cell-icon" :value="n"
title="标题">
</mt-cell-swipe>
methods: {
deleteCell: function (val) {
console.log('delete', val)
}
}
模板部分代码:<mt-cell-swipe v-for="(n, index) of dataList" :right="rightButtons" :key="index">{{n}}</mt-cell-swipe>
created钩子函数部分代码:this.rightButtons = [
{
content: 'Mark as Unread',
style: { background: 'lightgray', color: '#fff' }
},
{
content: 'Delete',
style: { background: 'red', color: '#fff' },
handler: (index) => {
this.danjuList.splice(index, 1)
}
}
];
循环时候给key绑定index,然后直接splice数组,也能达到效果。
Most helpful comment
@ECHOyougf 我是这样处理的
在template 里面
<mt-cell-swipe :id="i.labelId" class="label_cells_swipe" :right="[ { content: '删除', style: { background: 'red', color: '#fff' }, handler: () => labelDel(i.labelId) } ]">
在rightbutton里面加id
然后在methods里面写上删除的办法
// 删除标签 labelDel(id) { for (var i = 0; i < this.all_label.length; i++) { if (this.all_label[i].labelId == id) { this.all_label.splice(i, 1); break; } } this.delLabel(id) }