1.promise化
function util() {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.onload = function (e) {
let data = e.target.result
let img = new Image()
img.src = data
img.onload = function () {
resovle({
width: img.width,
height: img.height
})
console.log('width', img.width)
console.log('height', img.height)
}
}
reader.readAsDataURL(file)
})
}
2.调用
async function getImg() {
let img = await util()
console.log('width', img.width)
console.log('height', img.height)
}