Your problem here extends from the definition for await
...
The await
operator is used to wait for a Promise
The Image.prototype.onload
property is not a promise, nor are you assigning it one. If you're wanting to return the height
property after loading, I would instead create a Promise
...
addImageProcess(src){
return new Promise((resolve, reject) => {
let img = new Image()
img.onload = () => resolve(img.height)
img.onerror = reject
img.src = src
})
}
You would then use the following to access that value
tmp.addImageProcess(imageUrl).then(height => {
console.log(height)
})
or, if within an async
function
async function logImageHeight(imageUrl) {
console.log('height', await tmp.addImageProcess(imageUrl))
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…