博客
关于我
微信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/

你可能感兴趣的文章