为什么setData赋值后打印是undefined呢?

小程序 文章 2022-02-24 10:20 691 0 全屏看文

AI助手支持GPT4.0

为什么setData赋值后打印是undefined呢?Why is printing undefined after setData assignment?

为什么setData赋值后打印是undefined呢?

在onload函数里接收传过来的参数options

this.setData({a:options})

console.log(a)

这里的a是undefined,为什么呢,请问怎么解决

Receive the passed parameter options this in the onload function setData({a:options}) console. Log (a) here a is undefined. Why? How to solve it

回答:

社交恐怖分z:
onLoad(options) {  this.setData({    a: options  }, () => {   console.log(this.data.a)  })}
小黎:

因为a没有定义啊 应该是this.data.a

brave:
console.log(this.data.a)

-EOF-

AI助手支持GPT4.0