this.setData赋值之后, 立即this.data,能够获取到变化到值么?

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

比如:当前this.setData({ a : 1}),这时候能立即取到 this.data.a 的变化的值么??

onShow(){

let a = 0

this.setData({

a: 1

})

this.data.a 是否就能取到已变化到值呢?

}

5 回复
yang39
yang392 楼6 年前

setData是有成功回调hook的,

你可以这么写

let a = 0

this.setData({a}, function(){

console.log(this.data.a)

})

yonghe
yonghe3 楼6 年前

你代码都写出来了,你试试啊

odai
odai4 楼6 年前
this.setData({a:1},()=>{

console.log(this.data.a)

})

楼上杨泉的操作是目前主流并且推荐的代码

chao44
chao445 楼6 年前

你试试看,我也不知道