uniapp获取用户信息 getuserinfo

<button open-type="getUserInfo" class="user-mask" @getuserinfo="toLogin" withCredentials="true"></button>

toLogin(fn){
                console.log('111111111111 toLogin');
                let self = this;
                uni.login({
                    provider: 'weixin',
                    success: function (loginRes) {
                        console.log('AAAAAAAAAAAA');
                        console.log('toLogin==========22222', loginRes);
                        //self.code = loginRes.code;
                        self.loginEvent(loginRes.code, fn); //用code去创建用户信息,或者查询用户的基本信息
                        uni.getUserInfo({
                            provider: 'weixin',
                            success: function (infoRes) {
                                console.log('用户昵称为:' + infoRes.userInfo.nickName);
                                debugger
                                console.log('授权登录成功' + infoRes.userInfo);
                                console.log('222222222222222' + JSON.stringify(infoRes));
                                //let data = self.formatOtherLogin(Object.assign(infoRes));
                                self.saveUserInfo(Object.assign(infoRes)); //todo 有效代码
                                //self.getUni(Object.assign(infoRes));
                            },
                            fail: function () {
                                console.log('3333333333');
                            },
                            complete: function () {
                                console.log('44444444444444');
                            }
                        });
                    }
                });

            },

推荐阅读更多精彩内容