全局变量在then内赋值后在函数外调用内容为空?
发布于 5 年前 作者 min90 9890 次浏览 来自 官方Issues

var dm

db.collection(‘zhongdui’).where({

_openid: this.data.openid

}).get().then(res => {dm=res.data[0],console.log(dm)})  //打印结果为{duiming: {…}}

console.log(dm)   //打印结果为undefined

3 回复

如果不为空,才是出错了。

xxxx: async function(){

    var res = await db.collection(…)…get(),

    dm = res.data[0]

    console.log(dm)

}

同步异步问题

回到顶部