formSubmit: function (e) {
this.setData({
updata:e.detail.value
})
console.log('form发生了submit事件,携带数据为:', this.data.updata)
wx.navigateBack({
delta:1
})
},
formReset: function (options) {
console.log('form发生了reset事件')
wx.navigateBack({
delta: 1
})
},
调试器输出:
这个好像我之前也有遇到过,我是通过状态将它锁住的
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
谢谢啊,
<form bindsubmit="formSubmit" bindreset="formReset">
<view class="weui-cell ">
<view class="weui-cell__hd">
<view class="weui-label">设备名称</view>
</view>
<view class="weui-cell__bd">
<input name="{{string['name']}}" class="weui-input" placeholder="请输入" />
</view>
</view>
<view class="weui-cells__title">以下节点是否投用</view>
<view class="weui-cells weui-cells_after-title">
<checkbox-group name="{{string['use']}}" bindchange="checkboxChange">
<label class="checkbox" wx:for="{{items}}" wx:key="{{item.name}}">
<checkbox value="{{item.name}}" checked="{{item.checked}}" />{{item.value}}
</label>
</checkbox-group>
</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_switch">
<view class="weui-cell__bd">是否完成</view>
<view class="weui-cell__ft">
<switch checked="{{false}}" name="{{string['done']}}" />
</view>
</view>
</view>
<view class="weui-cells__title">情况描述</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell ">
<view class="weui-cell__bd">
<input name="{{string['desc']}}" class="weui-input" placeholder="情况描述"> </input>
</view>
</view>
</view>
<view class="weui-cell ">
<view class="weui-cell__hd">
<view class="weui-label">完成日期</view>
</view>
<view class="weui-cell__bd">
<picker name="{{string['due']}}" mode="date" value="{{date}}" start="2019-06-01" end="2020-09-01" bindchange="bindDateChange">
<view class="weui-input">{{date}}</view>
</picker>
</view>
</view>
<view class="btn-area">
<button type="primary" formType="submit" bindtap="formSubmit">Submit</button>
<button type="default" formType="reset" bindtap="formReset">Reset</button>
</view>
</form>
我找到原因了,是在form里写了bindsubmit="formSubmit",又在button里写了bindtap="formSubmit",
所以执行了两次。对form用法不熟练,大家了解一下,避免犯错。
提供一下可复现的代码片段
刚代码不全,补充了,代码片段怎么弄?情况就是一个form,提交按钮点一次,会执行两submit,两次传的值还不一样