wxml:
绑定数组元素的id和下标(index)
<view data-id="{{item.id}}" data-index="{{index}}" bindtap="handleDel">删除</view>
js:
listDataDel:原数组数据
listData:删除后并更新的数组数据
handleDel(event){
var idx = event.currentTarget.dataset.index;
var _this1 = this;
wx.showModal({
title: '提示',
content: '确定删除评论吗?',
success (res) {
if (res.confirm) {
_this1.$request({
url: '请求接口数据',
type: 'POST',
param: {
id: event.currentTarget.dataset.id
}
}).then(function (res) {
let listDataDel = _this1.data.listData;
listDataDel.splice(idx,1);
_this1.setData({
listData: listDataDel
})
})["catch"](function (error) {
console.log(error, 'error');
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},