<template>
<div>
<input type="file" @change="getImageWidth" />
<p v-if="imageWidth">图片宽度: {{ imageWidth }}px</p>
</div>
</template>
<script>
export default {
data() {
return {
imageWidth: null
};
},
methods: {
getImageWidth(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
this.imageWidth = img.width;
URL.revokeObjectURL(img.src); // 释放URL对象
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
}
}
};
</script>
03-16
1557
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-30
1761
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-11
1376
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-14
1903
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)