一、问题产生
小程序开发过程中,在使用小程序的模板下发功能时遇到这样一个问题:
核心错误在这句:"Cannot read property 'templateId' of undefined" 无法读取未定义的templateId。
我是将官方的小程序示例中模板消息下发模块的代码移植过来的,使用的是云调用中的模板消息下发,如图
将代码移植过来,自己创建目录文件,其中只用到js文件和html文件
修剪代码后的js代码
Page({
sendTemplateMessageViaCloudFunction(e) {
wx.cloud.callFunction({
name: 'openapi',
data: {
formId: e.detail.formId,
},
}).then((res) => {
console.log('[云调用] [发送模板消息] 成功: ', res)
}).catch(err => {
console.error('[云调用] [发送模板消息] 失败: ', err)
})
}
})
html代码
<form bindsubmit="sendTemplateMessageViaCloudFunction" report-submit>
<button form-type="submit" loading=