wxml:
<image src="{{attachurl}}{{vo.cover}}" class='list-img' bindload="imageLoad" data-index="{{ index }}" style="{{ images[index ].width }}rpx; height:{{ images[index ].height }}rpx;"></image>
js
imageLoad: function (e) {
console.log(e)
var $width = e.detail.width, //获取图片真实宽度
$height = e.detail.height,
ratio = $width / $height; //图片的真实宽高比例
var viewWidth = 718, //设置图片显示宽度,左右留有16rpx边距
viewHeight = 718 / ratio; //计算的高度值
var image = this.data.images;
//将图片的datadata-index作为image对象的key,然后存储图片的宽高值
image[e.target.dataset.index] = {
viewWidth,
height: viewHeight
},
console.log(image)
this.setData({
images: image
})
},