res返回的数据,在括号外获取不了?
发布于 4 年前 作者 ufan 8245 次浏览 来自 问答

 res返回的数据,在括号外获取不了? 

onload:function(){

  const db= wx.cloud.database()

db.collection("time").where(     

xxxx: msms //查询云数据库

)

.get()

.then(res=>{

console.log(res);

var mmn2=res.data[0].hhtd;     //hhtd为数据库中的字段

console.log("test 测试1",bh)

this.setData({

mmn2: res.data[0].hhtd

})

})

var wmmn2=this.data.mmn2 //获取不了mmn2,但能获取this.data????

console.log("test 测试1",wmmn2) //获取不了 wmmn2 ?????

}

3 回复

需要在 then 之外获取,知道在then能获取,也知道在其他函数中也可以获取,

只是不知道在then外怎么获取

建议了解一下js的异步执行

建议了解一下js的异步执行

回到顶部