Lógica de inicio de sesión de WeChat, donde esta imagen no se puede mostrar, no la he resuelto temporalmente

interfaz:

<view class="indexContainer">
  <image class="avatarurl" src="{
   
   {avatarUrl}}" wx:if="{
   
   {avatarurl}}">  
  </image>

  <text wx:if = "{
   
   {nickName}}">{
   
   {nickName}}</text>
 
  <button wx:if="{
   
   {!isPerm}}" open-type="getUserInfo" bindgetuserinfo = "handleUserInfo">login</button>
</view>

js 

// pages/index/index.js
//注册当前页面
Page({

  /**
   * 页面的初始数据
   */
  data: {
    message: "hello world",

    son:true,
    nickName:'',
    avatarUrl:'',
    isPerm:false    
    
  },
  handleUserInfo:function(res){
    // console.log(res)
    if(res.detail.userInfo){
      console.log(res)

      this.setData({
        nickName: res.detail.userInfo.nickName,
        avatarUrl:res.detail.userInfo.avatarUrl
      })
    }else{
      console.log("login fail" + res.detail.errMsg);
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.getUserInfo({
      withCredentials: true,
      success: (res)=> {

        this.setData({
          nickName: res.userInfo.nickName,
          avatarUrl: res.userInfo.avatarUrl,
          isPerm:true
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

Información de inicio de sesión recibida a través del botón

Si ya ha iniciado sesión, es decir, autorizado, ¡puede obtener la información del usuario directamente en el método onLoad!

isPerm se utiliza para determinar si se ha otorgado la autorización, a fin de determinar si se muestra el botón de inicio de sesión.

———————————————————————————————————————

 

El ejemplo anterior es muy simple, hay un problema con la visualización de la imagen, retrocedamos y continuemos

Supongo que te gusta

Origin blog.csdn.net/qq_15009739/article/details/111824902
Recomendado
Clasificación