微信小程序:删除时提示是否删除

代码如下:

wx.showModal({
      title: '提示',
      content: '确定要删除吗?',
      success: function (sm) {
        if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
          } else if (sm.cancel) {
            console.log('用户点击取消')
          }
        }
})

项目中使用:

deleteById(e) {
      console.log(e);
      this.QueryParam.baseId = e.currentTarget.dataset.id
      var that = this;
      wx.showModal({
        title: '提示',
        content: '确定要删除吗?',
        success: function (sm) {
          if (sm.confirm) {
              // 用户点击了确定 可以调用删除方法了
              request.postParam("/api/baseInfo/deleteBaseInfo",that.QueryParam,function(res){
                  console.log(res)
                  if(res.data.success){
                    wx.showToast({
                      title: "删除成功",
                      icon: 'none',
                      duration: 2000
                    })
                    that.getList(true);
                  }else{
                    wx.showToast({
                      title: "删除失败",
                      icon: 'none',
                      duration: 2000
                    })
                  }
              });
            } else if (sm.cancel) {
              console.log('用户点击取消')
            }
          }
        }) 
},

注意:var that = this;放在外面

原文地址:https://www.cnblogs.com/zwh0910/p/14244830.html