html:
<button hover-class="none" open-type="getUserInfo" @getuserinfo="cancel('允许')">点击显示微信头像</button>
js :
// 点击弹框的取消和允许
cancel: function(value) {
var _this = this;
if (value == '取消') {
this.isPopUp = false;
} else if (value == '允许') {
uni.getUserInfo({
provider: 'weixin',
success: infoRes => {
_this.user = infoRes.userInfo;
console.log(_this.user);
uni.login({
provider: 'weixin',
success: loginRes => {
uni.request({
url: '*********', // 后端给的登录接口
method: 'POST',
data: {
jsCode: loginRes.code, // 微信返回的 code
head_url: _this.user.avatarUrl, // 微信头像
nick_name: _this.user.nickName // 微信昵称
},
success: res => {
_this.token =