我写个微信小程序,要绑定一下本地账号和用户的微信头像,就调用了uni.getUserProfile()
如下
<view v-if="hasLogin && !hasWxOpenId" class="center-list-item border-bottom" open-type="getUserProfile" @click="bindWeixin">
<text class="list-icon"></text>
<text class="list-text">绑定微信账号</text>
<text class="navigat-arrow"></text>
</view>
bindWeixin() {
uni.getUserProfile({
desc: '获取用户头像,昵称等简单信息'
}).then(upRes => {
console.log('uni.getUserProfile() succeeded: upRes = ', upRes);
}).catch(upErr =>{
console.log('uni.getUserProfile() succeeded: upErr = ', upErr);
})
}
结果返回值居然是个数组。而且数组里第一个值是null,第二个才是真正的返回值。
uni.getUserProfile() succeeded: upRes = uni.getUserProfile() succeeded: upRes =
(2) [null, {…}]
0: null
1:
cloudID: "52_y8K......"
encryptedData: "......"
errMsg: "getUserProfile:ok"
iv: "BSym......"
rawData: "{"nickName":"......"}"
signature: "84e975......"
userInfo: {nickName: "......", …}
__proto__: Object
length: 2
难道不应该是个单独的返回值object吗?怎么成了数组?
而且,后来我还尝试了调用uni.login(),返回值也成了数组,而且也是第一个值为null
这个怎么破?
白银狮子头 (作者)
明白了,谢谢!
套用之后就没有这个问题了。看来是Promise-then-catch搞的。
但是为什么不能用Promise-then-catch, 而只能用await-success-fail?
明明规范里写的是是简单object返回,使用Promise-then-catch却能形成数组,令人迷惑。
我曾经有印象,规范里某个地方说,Uniapp的所有调用都已经Promise化了,这里却用出了区别
2022-01-10 16:42