无法通过全局变量获得openid?
发布于 5 年前 作者 taotian 10481 次浏览 来自 官方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 回复

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 使用

楼上好厉害,

回到顶部