实训日志day 4

本文记录了在微信小程序中开发mine页面的过程,包括使用wx.getSystemInfo获取手机信息,显示昵称和头像,以及设置背景图片和调整元素大小位置的实践。
摘要由CSDN通过智能技术生成

mine页面:显示手机信息,获取昵称和头像

1.wx.getSystemInfo(Object object)

获取系统信息

successfunction 接口调用成功的回调函数
failfunction 接口调用失败的回调函数
completefunction 接口调用结束的回调函数(调用成功、失败都会执行)

 

重要的js内容

  data: {
    uicon:'../../assets/icons/my.png',
    uname:'用户名',
    model:'',
    system:'',
    screenHeight:'',
    screenWidth:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this
    var _this = this;
    // 获取手机系统信息
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        _this.setData({
          model: res.model,
          system: res.system,
          screenHeight: res.screenHeight,
          screenWidth: res.screenWidth
        })
      }
    });
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              _this.setData({
                uicon: res.userInfo.avatarUrl,
                uname: res.userInfo.nickName
              })
            }
          })
        } else {
          bindGetUserInfo();
        }
      }
    });
  },

 wxml

<view class="container">
  <view class='bg'>
    <!-- <image class='auto-img' src='../../images/bg.jpg' /> -->

    <image class='usericon' src='{{uicon}}'></image>
    <text>{{uname}}</text>
  </view>
  <view>手机型号:{{model}}</view>
  <view>手机版本号:{{system}}</view>
  <view>手机屏幕分辨率:{{screenWidth}} * {{screenHeight}}</view>

  
</view>

mine页面存放背景图片 

<view class="container">
  <view class='bg'>
    <!-- <image class='auto-img' src='../../images/bg.jpg' /> -->

    <image class='usericon' src='{{uicon}}'></image>
    <text>{{uname}}</text>
  </view>

</view>

调节背景图片和昵称的大小位置

.container{
  width: 100%;
  height: 100%;
}
.auto-img{
  width: 100%;
  height: 100%;
  display: block;
}
.usericon{
  height:200rpx;
  width:200rpx;
  border-radius:50%;
}
.bg>text{
  color: white;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值