2018-06-25 微信授权按钮

2018-06-25  本文已影响0人  Avatar_c3b5

wxml:

<view class="header_top">
      <button open-type="getUserInfo" bindgetuserinfo="getUserInfo"><image src="{{userInfo.avatarUrl}}"></image></button>
      <!-- <button hover-class='hoverBtn' class="bianji">编辑</button> -->
    </view>
    <view class="headerBot">
      <button open-type="getUserInfo" bindgetuserinfo="getUserInfo"><view class="header_text">{{userInfo.nickName}}</view></button>
      <view class="header_ress">{{userInfo.city}}</view>
    </view>

wxjs:
var app = getApp();
Page({
  data: {
    userInfo: {
      avatarUrl:"../../images/steward.png",
      nickName:"获取头像昵称",
      city:"位置"
    },
  },
  onLoad: function () {
    var that = this;
    console.log(app.globalData.userInfo)
    if (app.globalData.userInfo) {
      that.setData({
        userInfo: app.globalData.userInfo,
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
        })
      }
    } else {
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
    })
  }
})

//修改默认button样式
button {
  margin: 0;
  background-color: #fff;
  padding: 0;
}
button::after{
border:none;
}
上一篇下一篇

猜你喜欢

热点阅读