首先,讲一下formId的用处,前端获取formId传给服务端,以便于服务端进行服务通知的推送使用.
下面讲一下formId的获取方法,通过form组件获取,官方文档贴上:
https://developers.weixin.qq.com/miniprogram/dev/component/form.html
请注意,官方文档的提示:
将组件内的用户输入的<switch/> <input/> <checkbox/> <slider/> <radio/> <picker/> 提交。
当点击 <form/> 表单中 formType 为 submit 的 <button/> 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。
也就是说,除了以上提到的组件之外,其他任何的组件都不能通过form组件来获取formId.
而且,在form组件的属性report-submit为false是,也是不返回formId的.
下面我贴一下我的form组件的使用:
.wxml:
<form bindsubmit='registerFormSubmit' report-submit='true'>
<view class='buttons'>
<button class='canclebtn' bindtap='verifyCancleAction'>取消</button>
<button class='confirmbtn' form-type='submit'>确定</button>
</view>
</form>
.js:
registerFormSubmit: function (e) {
// 打印formId
console.log(e.detail.formId,);
},
verifyCancleAction: function () {
},
Form的使用很简单.主要是读懂并且注意API文档中的细节,就ok了.
谢谢大家~