【发布时间】:2019-10-19 16:11:42
【问题描述】:
return <img {...props} onLoad={event => {
console.log(event.target.naturalWidth)
}}/>
我想在 TypeScript React 中检索 naturalWidth 和 naturalHeight。
但是卡住了,TypeScript 找不到那个属性。
如何在 TypeScript React 中检索 naturalWidth 和 naturalHeight?
【问题讨论】:
-
你可以使用 let image = event.target 作为 HTMLImageElement; console.log(event.target.naturalWidth);在 onload 函数体内。
-
@Ganeshchaitanya 谢谢,我认为这是唯一的方法。
标签: html reactjs image typescript