微信小程序自动获取微信用户头像

Xml页面:

<view class="userinfo">

      <open-data type="userAvatarUrl" class="img" ></open-data>

        <image class="userinfo-avatar" ></image>

    </view>

css页面:

.userinfo {

  margin-left: 48rpx;

  margin-top: 48rpx;

  width: 120rpx;

  height: 120rpx;

  background:  rgba(42, 192, 206, 1);

  display: flex;

  flex-direction: column;

  align-items: center;

  border-radius: 60rpx;

}

.userinfo-avatar {

  width: 128rpx;

  height: 128rpx;

  margin: 20rpx;

  border-radius: 50%;

}

.img{

  width: 120rpx;

  height: 120rpx;

}

Js页面:

data: {

    navHeight: app.globalData.statusBarHeight * 2 + 86,

    nowUserId: app.globalData.userId,

    canIUse: wx.canIUse('button.open-type.getUserInfo'),

    hasUserInfo: false,

  },

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容