收藏
回答

为什么forsumit提交没东西出来?

    wxml
<form bindsubmit="formSubmit">
   <view class="section">
      <view class="section-title">生日</view>
      <view class="display" wx:if="{{changeOrSubmit}}" style="color: {{birthday ? '#000' : '#666'}}">{{birthday || '未设置出生日期'}}</view>
      <picker mode="date" start="1990-09-01" end="2020-09-01" data-type="birthday" bindchange="userInput" value="{{birthday}}" wx:if="{{!changeOrSubmit}}">
        <view class="picker" style="color: {{birthday ? '#000' : '#888'}};">{{birthday || '请输入出生日期'}}</view>
      </picker>
   </view>
   <view class="btn-area">
     <button formType="submit" type="primary">{{changeOrSubmit ? '修改' : '提交'}}</button>
   </view>
</form>
js
userInput: function (e) {
    console.log(e,"123")
    var self = this;
    var type = e.currentTarget.dataset.type;
    switch (type) {
      case 'birthday':
        console.log(e.detail.value)
        self.setData({ birthday: e.detail.value });
        break;
     
    }
  }
 formSubmit: function (e) {
   console.log(e.detail.value)
    console.log(app.userInfo,"用户信息")
    console.log(e.detail.value.birthday,"生日")       undefined
    // 只有当前处于提交状态才会执行下面的代码
    if (!this.data.changeOrSubmit) {
      db.collection('userinfo').where({
        _id: app.userInfo._id
      }).update({
        data:
          birthday: e.detail.value.birthday,      
        }
      }).then(res=>{
        app.userInfo.nickName=this.data.nickName
        wx.showModal({
          title: '提示',
          content: '修改成功',
          success: function (res) {
            console.log(res)
            if (res.confirm) {
              console.log('用户点击确定')
            }
          }
        })
      })
     this.setData({
       changeOrSubmit: true
     })
    } else {
      this.setData({
        changeOrSubmit: !this.data.changeOrSubmit
      });
    }
  },

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签