const getFileObj = async (file)=>{
const reader = new FileReader(); // 创建文件对象
const imgObj = await new Promise((resolve, reject) => {
reader.onload = function (evt) {
const image = new Image();
image.src = evt.target.result;
image.onload = function () {
// 返回图片的宽高
resolve({
width: this.width,
height: this.height
})
}
}
reader.readAsDataURL(file)
})
return imgObj;
}
//上传文件
getFileObj(file).then(res=>{
console.log(res); // 返回 {width, height}
});