小程序 表单 formId 为 the formId is a mock one

微信小程序使用模板消息需要使用支付prepay_id或表单提交formId,

要获得 formId 需要在 form 标签中声明属性 report-submit="true"
.wxml 代码如下:

<form report-submit="true" bindsubmit="formSubmit" bindreset="formReset">
  <label>姓名</label>
  <input name="name" />
  <button formType="submit" type="primary">提交表单</button>
</form>

.js 代码如下:

formSubmit: function (e) {
  // 获取表单id
  formId = e.detail.formId;
  // 非真机运行时 formId 应该为 the formId is a mock one
  console.log('表单id:', formId );
}

在微信开发者工具中运行获取的 formId 为 the formId is a mock one ,要获得真实有效的 formId 需要在真机上运行。

原文链接:小程序 模板消息 表单 formId 为 the formId is a mock one | 李晨亮的博客(附:模板消息发送条件)

猜你喜欢

转载自blog.csdn.net/lichenliang666/article/details/79346643
今日推荐