如何在微信小程序中实现确认框

如何在微信小程序中实现确认框?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

核心代码如下:

delType:function(e){

 var typeId = e.currentTarget.dataset['id'];

 console.log("delete:"+typeId)


 wx.showModal({
  title: '提示',
  content: '确认要删除该支出类型?',
  success: function (res) {
   if (res.confirm) {
    console.log('用户点击确定')

    wx.request({

     url: getApp().globalData.urlPath + "spendingType/delete",
     method: "POST",
     data: {
      typeId: typeId
     },
     header: {
      "Content-Type": "application/x-www-form-urlencoded"
     },
     success: function (res) {
      console.log(res.data.code);
      if (res.statusCode == 200) {

       //访问正常
       if (res.data.code == "000000") {
        wx.showToast({
         title: "删除成功,返回支出类型列表",
         icon: 'success',
         duration: 3000,
         success: function () {

          wx.navigateTo({
           url: '../type/type'
          })
         }
        })

       }
      } else {

       wx.showLoading({
        title: '系统异常',
        fail
       })

       setTimeout(function () {
        wx.hideLoading()
       }, 2000)
      }

     }
    })


   } else if (res.cancel) {
    console.log('用户点击取消')
   }
  }
 })

}

wxml代码如下:

<text bindtap='delType' data-id="{{item.typeId}}">删除</text>

看完上述内容,你们掌握如何在微信小程序中实现确认框的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!