首页 > 解决方案 > 反应构造函数中的错误

问题描述

我的元素中有这个构造函数

constructor(props) {
    super(props);

    if (!window.stepThree) {
        window.stepThree = {
            activeLinks: []
        }
    }

    this.state = {
        full: window.stepThree.full || "-",
        city_type: window.stepThree.city_type || "-",
        passportComment: window.stepThree.passportComment || "-",
        passportUnit: window.stepThree.passportUnit || "-",
        snils: window.stepThree.snils || "-",
        order_type_id: 7,
        phone: "",
        choosenOkveds: window.stepThree.choosenOkveds ? JSON.parse(window.stepThree.choosenOkveds) : [],
    };

    window.id = window.location.hash.substr(window.location.hash.indexOf('=')).substr(1);
    if (window.id) {
        axios.get('/api/orders/get/' + window.id).then(response => {
            var json = JSON.parse(response.data.data.json);
            this.setState({
                settlement_type: json.individuals[0].settlement_type,
                settlement: json.individuals[0].settlement,
                city_type: json.individuals[0].city_type,
                choosenOkveds: json.choosenOkveds ? JSON.parse(json.choosenOkveds) : ""
            });
            window.stepThree = response.data.data;
            window.stepThree.json = json;
        });
    }

    if(!window.stepThree.activeLinks[3]) {
        window.stepThree.activeLinks.push('/preparation/stepFour/editIP')
    }

    this.showSubList = this.showSubList.bind(this);
    this.treeOkveds = this.treeOkveds.bind(this);
}

但是根据this.state,当我访问此页面的链接时,出现错误“尝试更新StepFive已卸载(或未能安装)的组件。”。但是重新加载后它工作正常。我该如何解决这个错误?

标签: reactjs

解决方案


推荐阅读