I want to load the picture before render and put it in state, and then render, it, but render is still slow.

componentWillMount() {
        const _self = this;
        var qs = (location.search.length>0?location.search.substring(1):"");
        var args = {};
        var items = qs.length?qs.split("&"):[];
        var item = null;
        var name = null;
        var value = null;

        var len = items.length;
        for (var i = 0; i < len; iPP) {
            item = items[i].split("=");
            name = decodeURIComponent(item[0]);
            value = decodeURIComponent(item[1]);
            if (name.length) {
                args[name] = value;
            }
        }
        let keyValue = args["key"];

        console.log(" == ", keyValue)

        _self.setState({
            //url: "http://static.kube.univer"+keyValue,
        })
    }
<div
                        className={"image_describe"}
                    >
                        <div className={"image_describe_information"}>
                            <div></div>
                            <div
                            >{image}</div>
                        </div>
                    </div>
Apr.05,2021

the speed at which pictures are loaded depends mainly on the speed of the Internet.
and never call setState in componentWillMount


what does it mean that render is still slow? How do you perceive slowness. In addition, it is not recommended to preload resources in this way, there are many ways. You can search the Internet, a lot.

in addition, if you have to do this, it is recommended that you put the code in componentDidMount or determine whether the current component has been properly mounted with (mounted)

when you setState.

posture is not correct.


componentWillMoun t has been abandoned since version 16.3.
although you set state before render , it is still url , and does not put the picture data in state , while in render you still have to load pictures through the network.
then you can use the load-lazy component. The effect will be much better this way.

Menu