https://github.com/Tencent/wepy/issues/1379
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">用户授权</button>
微信团队修改了wx.getUserInfo 接口,要求使用button组件,
wepy使用@来绑定事件,我试过@getuserinfo和@bindgetuserinfo,这两种方式都不能 用
请问bindgetuserinfo在wepy该怎么写
正确回调写法:
<button open-type="getUserInfo" @getuserinfo="bindGetUserInfo">用户授权</button>
//授权回调
bindGetUserInfo(e) {
this.doLogin();
if (e.mp.detail.userInfo) {
//用户按了允许授权按钮
this.doLogin();
} else {
//用户按了拒绝按钮
wx.hideLoading();
}
}
doLogin() {
if (this.nickName === "立即登录") {
wx.showLoading({
title: "正在登录"
});
//授权直接获取用户,未授权引导设置授权后获取用户
wx.getSetting({
success: res => {
if (res.authSetting["scope.userInfo"]) {
this.loginout = false;
wx.getUserInfo({
success: res => {
const userInfo = res.userInfo;
const nickName = userInfo.nickName;
this.nickName = userInfo.nickName;
this.avatarUrl = userInfo.avatarUrl;
wx.setStorageSync("islogin", true);
wx.setStorageSync("nikeName", nickName);
});
});
wx.hideLoading();
}
});
}
}
});
}
},
网友评论