无法通过全局变量获得openid?

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

wx.login({

success(res) {

//发起网络请求

wx.cloud.callFunction({

name: ‘login’

}).then(res => console.log(res)).then(db.collection(‘zhongdui’).add({

data: {

openid: res.result

}

})).then(

kkid = res.result,

)

}

})

其中kkid为全局变量,函数运行后kkid的值为undefined

2 回复
nxie
nxie1 楼6 年前

wx.login({

    success(res) {

        //发起网络请求

        wx.cloud.callFunction({

            name: ‘login’

        }).then(res2 => {

            console.log(res2)

            kkid = res.result

            return db.collection(‘zhongdui’).add({

                data: {

                    openid: res.result

                }

            })

        })

    }

})

如果要在wx.login之外能打印kkid 值,还需配合async / await 使用

taolai
taolai2 楼5 年前

楼上好厉害,