js:
Page({
formSubmit: function(e) {
console.log(app.globalData.userInfo.nickName);
wx.showToast({
title: '评论成功',
icon: 'success',
duration: 3000
})
var that = this;
var liuyantext = e.detail.value.liuyantext; //获取表单所有name=liuyantext的值
console.log('视频id' + that.data.id);
console.log('留言number:' + that.data.number);
wx.request({
url: 'https://xxxx/comment',
data: {
content: liuyantext,
number: that.data.number,
id: that.data.id
},
header: {
'Content-Type': 'application/json'
},
success: function(res) {
// console.log(res.data)
that.setData({
showOrHidden: true,
re: res.data,
keyValue:'',
photo2: res.data.result.comment.photo,
nickname2: res.data.result.comment.nickname,
date2: res.data.result.comment.date,
comment2: res.data.result.comment.comment
})
wx.hideToast();
console.log(res);
}
})
},
})
错误提示:
WAServiceMainContext.js:2 ReferenceError: app is not defined
at Br.formSubmit (community.js? [sm]:4)
at Object.r.safeCallback (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)
at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2
at wn (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)
at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2
at g (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)
at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2
at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2
at WAServiceMainContext.js:2
at a (VM16 asdebug.js:10)(env: Windows,mp,1.06.2301160; lib: 2.19.4)
文件开头定义这个变量没有?
const app = getApp();
第一行少代码了 const app = getApp() 代码抄的没灵魂