return <img {...props} onLoad={event => {
console.log(event.target.naturalWidth)
}}/>
我想在TypeScript React中检索naturalWidth和naturalHeight。
但是卡住了,TypeScript找不到该属性。
如何在TypeScript React中检索naturalWidth和naturalHeight?
答案 0 :(得分:2)
您可以通过HTMLImageElement
(而非event.currentTarget
)访问event.target
,因此应该可以:
return <img {...props} onLoad={event => {
console.log(event.currentTarget.naturalWidth)
}}/>
答案 1 :(得分:0)
您可以尝试innerWidth和innerHeight。
console.log(event.target.innerWidth)