我通过云函数获取了一个数组,并放到了userinfo中。但是console显示的时候报错。
代码如下:
wx.cloud.callFunction({
name: 'test',
complete: res => {
console.log('callFunction test result: ', res.result)
userinfo : res.result
console.log(userinfo[OPENID])
}
})
console.log的报错如下:
ReferenceError: userinfo is not defined
at Function.complete (index.js? [sm]:116)
at :10410/appservice/<api cloud.callFunction complete callback function>
at Function.<anonymous> (WAServiceMainContext.js?t=wechat&s=1695891408658&v=3.1.0:1)
at <anonymous>:1:165785
at F (<anonymous>:1:165632)
at <anonymous>:1:165776
at W (<anonymous>:1:166290)
at j (<anonymous>:1:166419)
at <anonymous>:1:204438(env: Windows,mp,1.06.2308310; lib: 3.1.0)
userinfo在最开始时定义了的。
data: {
userinfo:[]
},
我这个问题可能是个菜鸟问题,请各位大侠指点。
console.log("openid:"+res.result[0].openid)
userinfo : res.result
先报个班吧,
这个 userInfo 是什么东西,还有贴代码可以选择代码选项
const _this = this; wx.cloud.callFunction({ name: 'test', complete: res => { console.log('callFunction test result: ', res.result) _this.setData({ userinfo : res.result }); console.log(_this.data.userinfo) } })
----------------------------------
如何取到数据还需要确定结果中的数据结构是什么样的
TypeError: Cannot read property 'setData' of undefined
at Function.complete (index.js? [sm]:115)
at :10410/appservice/<api cloud.callFunction complete callback function>
at Function.<anonymous> (WAServiceMainContext.js?t=wechat&s=1695891408658&v=3.1.0:1)
at <anonymous>:1:165785
at F (<anonymous>:1:165632)
at <anonymous>:1:165776
at W (<anonymous>:1:166290)
at j (<anonymous>:1:166419)
at <anonymous>:1:204438(env: Windows,mp,1.06.2308310; lib: 3.1.0)