Jos*_*ang 4 html image typescript reactjs
return <img {...props} onLoad={event => {
console.log(event.target.naturalWidth)
}}/>
Run Code Online (Sandbox Code Playgroud)
I want to retrieve naturalWidth & naturalHeight in TypeScript React.
But got stuck, TypeScript can't find that property.
How do I retrieve naturalWidth & naturalHeight in TypeScript React?
您可以HTMLImageElement
通过event.currentTarget
(而不是event.target
)访问,所以这应该可以工作:
return <img {...props} onLoad={event => {
console.log(event.currentTarget.naturalWidth)
}}/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3983 次 |
最近记录: |