原理: 原图宽/原图高 = 屏幕宽/适应屏幕宽后的图片高
wxml
<swiper style="height:{{imgh==0?200:imgh}}" indicator-dots="{{indicatorDots}}" autoplay="true" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{图片数组***》》此处替换}}" wx:key="*this">
<swiper-item>
<image bindload="imageload2" style="height:{{imgh==0?200:imgh}}" bindtap="toApplyBrand" src="{{URL图片路径》》》*此处替换}}"></image>
</swiper-item>
</block>
</swiper>
JS
Page({
data: {
imgh:'',
indicatorDots: true,
vertical: false,
autoplay: false,
interval: 2000,
duration: 500,
},
imageload2: function (e) {//获取图的高度
let swiperHeight = this.data.imgh;
let imgWidth = e.detail.width; //获取图片原始宽度
let imgHeight = e.detail.height; //图片原始高度
var width = wx.getSystemInfoSync().windowWidth;
//获取可使用窗口宽度
console.log('可用窗口 高度-->',width);
swiperHeight = width * imgHeight / imgWidth ;
console.log("swiperHeight", swiperHeight)
this.setData({
imgh: swiperHeight+'px'
})
},
})