小程序获取屏幕宽度

https://developers.weixin.qq.com/miniprogram/dev/api/base/system/system-info/wx.getSystemInfo.html

写在app.js里了 随时可以调用

 onShow: function (options) {
    console.log("app-onShow");
    let that = this;
    //显示客服入口
// 获取系统参数
    wx.getSystemInfo({
      success: res => {
        console.log(res)
        that.globalData.screenWidth = res.screenWidth;
        that.globalData.screenHeight = res.screenHeight;
      }
    })
  }
  data: {
    screenWidth: app.globalData.screenWidth,
   
  },
<swiper indicator-dots="true" autoplay="true" interval="2000" duration="500" indicator-color="rgba(0,0,0,0.5)" indicator-active-color="red" circular="true" style='height:{{screenWidth * 0.48}}px'>
  <block wx:for="{{list}}" wx:key='*this'>
    <swiper-item>
      <image src="{{item.image}}" mode='aspectFill'  class="slide-image" style="width: 100%;height:{{screenWidth * 0.48}}px"/>
    </swiper-item>
  </block>
</swiper>
发布了69 篇原创文章 · 获赞 17 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/Acitylion/article/details/98177893