码迷,mamicode.com
首页 > 其他好文 > 详细

小程序获取用户信息

时间:2018-07-16 23:07:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:UNC   fun   scope   info   func   头像   net   tin   url   

    <!--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

小程序获取用户信息

标签:UNC   fun   scope   info   func   头像   net   tin   url   

原文地址:https://www.cnblogs.com/anxiaoyu/p/9320685.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!