微信小程序 制作微信一键登录按钮

wxml

  <view class="content_3">
    <button open-type="getUserInfo" type="primary" lang="zh_CN" bindgetuserinfo="onGotUserInfo">
      <image class="btnImg" src="../../images/login/wechat.png"></image>
    微信用户一键登录</button>
    <view class="tip">
      <text>点击登录,即代表已阅读并同意</text><text style="color:#5FCDED" bindtap="userAgreement">《用户注册协议》</text>
    </view>
    <view class="phone_login" bindtap="phoneLogin">
      <text>输入手机号码登录/注册</text>
    </view>
  </view>

wxss

.btnImg {
  margin-right: 8rpx;
  width: 48rpx;
  height: 46rpx;
}


.content_3 button {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
.content_3 {
  padding: 0% 5%
}

js

  onGotUserInfo: function(e) {
    console.log(e)
    if (e.detail.errMsg != "getUserInfo:fail auth deny"){
      /** 获取用户信息 **/
      wx.getUserInfo({
        success: res => {
          console.log(res)
          app.globalData.userInfo = res.userInfo
          wx.setStorage({
            key: 'userInfo',
            data: res.userInfo,
          })
        }
      })
    }
  },
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值