微信小程序动态监听页面的高度-自动修改页面高度

有的时候给小程序页面设置背景颜色,但是有时候页面没有那么多数据量,没有撑满一屏,需要设置页面的高度为一屏高度

data: {
    height: 0,
}
/**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: `${height}rpx`
        });
      }
    });
  },
<view class="index" style="height:{{height}}"></view >

 

posted @ 2023-07-10 15:47  JackieDYH  阅读(207)  评论(0编辑  收藏  举报  来源