1.在全局app.js中获取设备的宽度

 globalData: {    userInfo: null,    sysWidth:wx.getSystemInfoSync().windowWidth, //图片宽度  }2.在其他js中加载时设置高度变量 如a.js

   var appInstance = getApp();    console.log(appInstance.globalData.sysWidth);     this.setData({      sysWidth: appInstance.globalData.sysWidth    });

3.在引用的wxml中设置 style样式

<swiper autoplay="auto" interval="5000" duration="500" current="{{swiperCurrent}}" bindchange="swiperChange" style='height:{{sysWidth}}px'>  这里实现的是swiper的宽度是100%,的正方形轮播,效果如图

小程序

当然你也可以设置成80%等等,原理相同

解决问题了请点赞哈哈

TAG标签: 微信小程序长方形图片

http://www.xiaochengxub.com/read-99777.html