第一個小程序,獲取用戶名和用戶頭像


 

 

 

<!--pages/index/index.wxml-->
<!-- 內容封裝在view中 -->
<view class="content">
  <image src='{{src}}'>

  </image>
  <text>
    歡迎光臨
  </text>
  <text class="name">
    {{name}}
  </text>
  <button open-type="getUserInfo" 注意:此接口有調整,使用該接口將不再出現授權彈窗  bindgetuserinfo="getmyinfo">
   點擊獲取頭像和昵稱
  </button>
  <!-- open-type 激活獲取微信用戶的功能 -->
  <!-- bindgetuserinfo 將獲得的數據傳遞給函數 -->
</view>

<!-- 用到圖片 文字 按鈕 -->

js

/**
   * 頁面的初始數據
   */
  data: {
    name:"",
    src:"/images/weixin.jpg"
  },
  getmyinfo:function(e){
    console.log(e.detail.userInfo);
    let info = e.detail.userInfo.nickName;
    this.setData({ 修改當前數據
      name:info,
      src:e.detail.userInfo.avatarUrl
    })
  },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM