uni.showModal 点击确认提示 Cannot read property ‘ ‘ of undefined

该错误是是因为 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('用户点击取消');
        }
    }
});

猜你喜欢

转载自blog.csdn.net/weixin_44640323/article/details/112700555
今日推荐