前提条件:在特点大小的框中,图片的宽和高100%在框中展示
问题:获取上传图片的尺寸,并让多个框在图片上展示
期望结果:
解决方法:
<div
ref="box"
:style="{
top: `${item.boxTop}`,
left: `${item.boxLeft}`,
width: `${item.boxWidth}`,
height: `${item.boxHeight}`,
}"
class="select-img"
v-for="(item, index) in boxs"
:key="index"
></div>
this.boxPoint([[1014,124,153,202],[900,600,153,202],[600,124,153,202]]);
boxPoint(point) {
const img = new Image();
img.onload = () => {
const { width, height } = img;
this.boxs = point.map((item) => {
return {
boxTop: `${(item[1] / height) * 100}%`,
boxLeft: `${(item[0] / width) * 100}%`,
boxHeight: `${(item[3] / height) * 100}%`,
boxWidth: `${(item[2] / width) * 100}%`,
};
});
};
img.src = this.imgUrl;
},