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. 
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45f5e-438b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45f5e-438b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?