<!--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 }) },