Model bullet box of WeChat applet

There are generally two types of expression forms for applet models:

1. The first type:

wxml:
<button type="primary" bindtap="click">按钮</button>
<modal class="modal"  title='这是标题' confirm-text="确认" hidden="{
   
   {modalHidden}}" cancel-text="取消" bindcancel='modalCancel' bindconfirm='modalConfirm'>
这里是内容
</modal>

js:
Page({
  data: {
      modalHidden:true 
  }, 

  click:function(){
      
      this.setData({
          modalHidden:!modalHidden
        });

  },

  //模态框取消
  modalCancel(){
    wx.showToast({
      title: '取消提交',
      icon:'none'
    })
    this.setData({
      modalHidden:true, //都可以
    })
  },
})

2. The second type:

js is different:

click:function(){
    wx.showModal({
        title: '提示',
        content: '这是一个弹窗',
        success: function(res) {
           if (res.confirm) {
              console.log('用户点击确定')
           } else if (res.cancel) {
              console.log('用户点击取消')
           }
        }
    })
}

Guess you like

Origin blog.csdn.net/TC_DESpipi/article/details/126674212