该错误是是因为 success 后面是 function,里面的 this 指向错误,如下
uni.showModal({
title: '提示',
content: '确认删除',
success: function (res) {
if (res.confirm) {
this.$requst.login(this.apiUrl+'api/member/delcart',{
id:id
}).then(res=>{
this.carlist.splice(index,1)
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
解决办法 function 改为箭头函数
uni.showModal({
title: '提示',
content: '确认删除',
success: res => {
if (res.confirm) {
this.$requst.login(this.apiUrl+'api/member/delcart',{
id:id
}).then(res=>{
this.carlist.splice(index,1)
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});