博客
关于我
微信getUserInfo接口
阅读量:157 次
发布时间:2019-02-28

本文共 972 字,大约阅读时间需要 3 分钟。

参考:

https://ask.dcloud.net.cn/question/118013

 

 

            <!-- 旧版本方式 -->

            <block v-if="canIUseProfile==false">
                <button class="form-button" open-type="getUserInfo" @getuserinfo="getUserInfo" lang="zh_CN">微信授权</button>
            </block>
            <!-- 新版本方式 -->
            <block v-else>
                <button class="form-button" @tap="getUserInfo">微信授权</button>
            </block>

        onLoad() {
            if (wx.getUserProfile) {
                console.log('--check getUserProfile--OK');
                this.canIUseProfile = true;
            }
        },
        methods: {
            // 授权个人信息
            getUserInfo(e) {
                //旧版本方式  
                if (this.canIUseProfile == false) {
                    //获取授权信息  
                    if (e.detail.userInfo) {
                        console.log('旧版本-用户允许了授权')
                        const { userInfo: {avatarUrl, nickName, gender, country, province, city} } = e.detail
                        ...
                    }
                }
else {
                    //新版本方式  
                    var that = this;
                    wx.getUserProfile({
                        desc: '用于完善用户资料',
                        lang: 'zh_CN',
                        success: function(res) {
                            console.log('新版本方式->用户允许了授权');
                            const { userInfo: {avatarUrl, nickName, gender, country, province, city} } = res
                            ...
                        },
                        fail: function(res) {
                            console.log('wx.getUserProfile=>用户拒绝了授权', res);
                        }
                    });
                }
            }
        }

 

转载地址:http://ykkj.baihongyu.com/

你可能感兴趣的文章
MySQL事务及其特性与锁机制
查看>>
mysql事务理解
查看>>
MySQL事务详解结合MVCC机制的理解
查看>>
MySQL事务隔离级别:读未提交、读已提交、可重复读和串行
查看>>
MySQL事务隔离级别:读未提交、读已提交、可重复读和串行
查看>>
webpack css文件处理
查看>>
mysql二进制包安装和遇到的问题
查看>>
MySql二进制日志的应用及恢復
查看>>
mysql互换表中两列数据方法
查看>>
mysql五补充部分:SQL逻辑查询语句执行顺序
查看>>
mysql交互式连接&非交互式连接
查看>>
MySQL什么情况下会导致索引失效
查看>>
Mysql什么时候建索引
查看>>
MySql从入门到精通
查看>>
MYSQL从入门到精通(一)
查看>>
MYSQL从入门到精通(二)
查看>>
mysql以下日期函数正确的_mysql 日期函数
查看>>
mysql以服务方式运行
查看>>
mysql优化--索引原理
查看>>
MySQL优化之BTree索引使用规则
查看>>