小程序 微信 授权回调

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();
            }
          });
        }
      }
    });
  }
},
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容