白银狮子头
白银狮子头
  • 发布:2022-01-10 01:25
  • 更新:2022-01-10 09:12
  • 阅读:543

uni.getUserProfile 为什么返回的是数组?

分类:uni小程序sdk

我写个微信小程序,要绑定一下本地账号和用户的微信头像,就调用了uni.getUserProfile()
如下

<view v-if="hasLogin && !hasWxOpenId" class="center-list-item border-bottom" open-type="getUserProfile" @click="bindWeixin">  
    <text class="list-icon">&#xe65f;</text>  
    <text class="list-text">绑定微信账号</text>  
    <text class="navigat-arrow">&#xe65e;</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

这个怎么破?

2022-01-10 01:25 负责人:无 分享
已邀请:
FullStack

FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866

uni.getUserProfile({  
desc: "登录",  
success: (res) => {  
console.log(res)  
}  
})  
  • 白银狮子头 (作者)

    明白了,谢谢!

    套用之后就没有这个问题了。看来是Promise-then-catch搞的。


    但是为什么不能用Promise-then-catch, 而只能用await-success-fail?

    明明规范里写的是是简单object返回,使用Promise-then-catch却能形成数组,令人迷惑。

    我曾经有印象,规范里某个地方说,Uniapp的所有调用都已经Promise化了,这里却用出了区别

    2022-01-10 16:42

该问题目前已经被锁定, 无法添加新回复