<image
v-if="record.reportPath"
:src="record.reportPath"
class="img"
:style="'height: ' + imgHeight + 'px'"
@load="onImgLoad"
@tap="previewImage(record.reportPath)"
@error="imageError"
></image>
onImgLoad(e) {
// 当图片加载完成后,获取图片的原始宽度和高度,并根据宽度计算出高度
const { width, height } = e.detail;
const box = document.getElementById("reportImg");
const boxWidth = parseFloat(window.getComputedStyle(box).width);
this.imgHeight = (boxWidth * height) / width;
},
previewImage(e) {
const imgArr = [e];
// 预览图片
uni.previewImage({
urls: imgArr,
current: 0,
fail: function (err) {
console.log(err.errMsg);
},
});
},
imageError() {
this.record.reportPath = "../../static/img/图片加载失败.png";
},