How to get the correct height before the react picture is loaded?

write the event of getting height in the onLoad of img. If the picture is too large and the event delay is very serious, how to solve it?

put the function of getting height in componentDidMount (), so you can"t get the correct height (the picture hasn"t been loaded yet)

how to solve it?

Apr.01,2021

set the image by default first. Can't you replace it after the picture has been loaded?


there is no width or height in the unloaded img,.

A usually feasible way to set width and height directly in css


{
width:725,
height:350,
src: "192.168.31.154:1234/logo.png",
name: "General logo"
}
Purple can meet your needs


you can refer to this https://blog.csdn.net/qq_4020.
better set delay or you can't get width and height


if it is your own server, you can return the width and height when you return the image, and there will be no problem.

if it is a picture from other places, it is not easy to deal with. You can uniformly set the height and width adaptively

.
1. 
Menu