获取图片信息,并赋值
vue:
<image
:src="url"
class="img"
:style="{
width: width,
height: height,
}"
/>
js:
data() {
return {
width: "",
height: "",
};
},
mounted() {
let that = this;
uni.getImageInfo({
src: url,
success: (image) => {
that.width = image.width + "rpx";
that.height = image.height + "rpx";
console.log(that.width, image.width, that.height, image.height);
},
});
},
css:防止横向图片超出显示
.img {
max-width: 100%;
max-height: 100%;
}