// 计算图片尺寸
export function asyncImgChecked(file, width, height) {
return new Promise((resolve) => {
const reader = new FileReader()
reader.readAsDataURL(file.raw) // 必须用file.raw
reader.onload = () => { // 让页面中的img标签的src指向读取的路径
const img = new Image()
img.src = reader.result
// console.log(`1当前文件尺寸大小:${img.width}×${img.height}`)
if (img.complete) { // 如果存在浏览器缓存中
if (img.width < width || img.height < height) {
resolve(false)
} else {
resolve(true)
}
} else {
img.onload = () => {
if (img.width < width || img.height < height) {
resolve(false)
} else {
resolve(true)
}
}
}
}
})
}
el-upload限制图片尺寸
于 2023-03-21 17:47:16 首次发布