anxiaoyu
    <!--wxml-->
    <!-- 如果只是展示用户头像昵称,可以使用 <open-data /> 组件 -->
    <open-data type="userAvatarUrl"></open-data>
    <open-data type="userNickName"></open-data>
    <!-- 需要使用 button 来授权登录 -->
    <button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>
    <view wx:else>请升级微信版本</view>

 

    //js
    Page({
      data: {
        canIUse: wx.canIUse(\'button.open-type.getUserInfo\')
      },
      onLoad: function() {
        // 查看是否授权
        wx.getSetting({
          success: function(res){
            if (res.authSetting[\'scope.userInfo\']) {
              // 已经授权,可以直接调用 getUserInfo 获取头像昵称
              wx.getUserInfo({
                success: function(res) {
                  console(res.userInfo)
                }
              })
            }
          }
        })
      },
      bindGetUserInfo: function(e) {
        console.log(e.detail.userInfo)
      }
    })

 转自https://blog.csdn.net/qq_24956631/article/details/80330605

分类:

技术点:

相关文章: