为什么form表单提交后,并没有自动刷新,有些数据还可以继续使用?
发布于 7 年前 作者 weigang 2566 次浏览 来自 官方Issues

这是我的html,用的是picker选择地址, form将其包含,提交表单时,将数据上传

      <view class="item_msg">收货地址(市)</view>
      <view class="section">
        <picker class="picker" name="id" bindchange="bindChange" value="{{city}}" range="{{cityList}}" range-key="name">
          <view class=" {{code==0 ? '':'hide'}} ">市:{{cityList[city].name}}</view>
          <!-- <view class=" {{code==0 ? 'hide':''}} ">市: {{provinceList.city}}</view> -->
        </picker>
      </view>
    </view>
    <view class="address_msg">
      <view class="item_msg">收货地址(区)</view>
      <view class="section">
        <picker class="picker" name="id" bindchange="bindChangeArea" value="{{area}}" range="{{areaList}}" range-key="name">
          <view class=" {{code==0 ? '':'hide'}} ">区:{{areaList[area].name}}</view>
          <!-- <view class=" {{code==0 ? 'hide':''}} ">区: {{provinceList.area}}</view> -->
        </picker>
      </view>
    </view>
    <view class="address_msg">
      <view class="item_msg">详细地址</view>
      <view class="section">
        <input class="detailed" name='detailed' value="{{provinceList.address}}" />
      </view>

这是js

  bindChange: function(e) {
   var cityName = this.data.cityList[e.detail.value].name
    console.log("城市"+cityName)
    let that = this
    // this.setData({
    //   city: e.detail.value
    // })
    console.log(this.data.cityList[e.detail.value].code)
    let citycode = this.data.cityList[e.detail.value].code
    wx.request({
      url: userUrl + '/api/area/selectAll/' + citycode,
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(e) {
        that.setData({
          areaList: e.data.data,
          cityName: e.data.data.name,
          // cityName : that.data.cityList[e.detail.value].name
        })
        console.log(e.data.cityList)
      },
    })
  },

  bindChangeArea: function(e) {
    var areaName = this.data.areaList[e.detail.value].name
    console.log("区" + areaName)
    console.log(this.data.areaList[e.detail.value].code)
    this.setData({
      area: e.detail.value,
     
    })
  },
  switch1Change: function(e) {
    console.log(e.detail.value);
    var radio = e.detail.value;

    if (radio == true) {

      isDefaul = 0

    } else {

      isDefaul = 1

    }
  },   
这里是表单
  formSubmit: function(e) {
    //修改保存,url,路径没改
    var address = e.detail.value.detailed
    console.log('城市' + address)
    var phone = e.detail.value.phone
    if (phone.length > 11 || phone.length < 11) {
      wx.showModal({
        content: '请填写正确的手机号',
      })
    } else if (cityName == 0) {
      wx.showModal({
        content: '请填写收货地址(市)',
      })
    } else if (areaName == 0) {
      wx.showModal({
        content: '请填写收货地址(区)',
      })
    } else if (address == 0) {
      wx.showModal({
        content: '请填写填写详细地址',
      })
    }
      console.log('form发生了submit事件,携带数据为:', provinceName, '和:', cityName);
      wx.request({
        url: userUrl + '/api/userAddress/update/' + id,
        header: {
          "Content-Type": "application/x-www-form-urlencoded",
          "ut": '97835e52d2b8f4d77f00d1b729b48bbd'
        },
        data: {
          contact: e.detail.value.username,
          mobile: phone,
          province: '',
          country: '',
          province: provinceName,
          city: cityName,
          area: areaName,
          address: address,
          zipcode: '',
          isDefault: isDefaul,
        },
        method: "PUT",
        dataType: 'json',
        responseType: 'text',
        success: function(e) {
          wx.navigateBack({
            delta: 1
          })
        },
        fail: function(e) {
          console.log(e);

问题是,当我第一次提交表单保存成功后,表单里的数据并没有失效,当下次提交如果不做选择时,提交的数据还是第一次的,但此时我什么都没有选。

我想问问大佬是什么原因。我觉得应该是var address = e.detail.value.detailed这样的声明有关,但又不知道怎么描述
2 回复

form的reset是重置刷新,并不会自动刷新。

提交之后的函数里面把该请的手动清掉,要不就重载页面

回到顶部