微信小程序getUserProfile,获取头像和昵称实现登录

 我做的是微信小程序getUserProfile登录实现,点击后可以获取微信头像和微信昵称

1.点击

2.点击授权

 

3.获取成功

 下面是代码

HTML代码

<view class="content">

<button bindtap="login" wx:if="{{isshow}}" class="an" >请点击登录</button>

<view class="userinfo" wx:else>

<image src="{{img}}" class="img"></image>

<view class="name">{{name}}</view>

</view>

</view>

css代码

.name{

  font-size: 25px;

}

.an{

background-color: rgb(247, 248, 248);

height: 40px;

top: 40px;

}

.img{

  width: 65px;

  height: 65px;

  display: inline-block;

  border-radius: 50%;

  overflow: hidden;

  border: 1px solid #131212;

  margin-right: 20px;

}

.userinfo{

 top: 10px;

  display: flex;

  flex-direction: row;

  width: 100%;

  height: 100px;

  align-items: center;  

}

.content{

  padding: 0px;

  margin-bottom: 30px;

  height: 100px;

 flex-direction: column;

 background-color: rgb(30, 211, 45);

  }

js代码

Page({

  data: {

    name:"",

    img:"",

    isshow:true,

  },

  login() {

    var that=this

    wx.getUserProfile({

      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写

      success: (file) => {

        console.log(file.userInfo.nickName)

        console.log(file.userInfo.avatarUrl)

        that.setData({

          img:file.userInfo.avatarUrl,

name:file.userInfo.nickName,

isshow:false,

        })

   

      }

    })

  },

})

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值