request请求数据之后 Appdata显示有数据 控制台输出却是undefined?

发布于 6 年前作者 wei672520 次浏览最后编辑 6 年前来自 issues

Appdata显示有数据 控制台输出却是Cannot read property ‘mes’ of undefined?

request请求数据之后 setData Appdata显示有数据 控制台打印不出来 前端显示没问题

3 回复
yong38
yong381 楼6 年前

异步的问题,最好改成同步。

shiwei
shiwei2 楼6 年前

onLoad : async function(){

    await this.getDetail()

    console.log(“onLoad”, this.data.mes)

}

xiuyingpeng
xiuyingpeng3 楼4 年前

this 指向问题!

你要写成

setTimeout(_=>{ console.log(this.data.mes)},3000)

或者

let that = this

setTimeout(function(){ console.log(that.data.mes) },3000)