react修改state的值

1.使用setState而不是直接等于。
2.
它还有两个参数可以用

        this.setState((prevState,props) => {
            const {xpath_info, list_tab_index, dataDemo, extractType, spider_state} = prevState;
            let select_data = dataDemo[list_tab_index].list_page_xpath;
            const {enu_list_xpath, current_xpath} = select_data;
            xpath_info.enu_list_xpath = enu_list_xpath;
            xpath_info.enu_field[extractType] = current_xpath;
            xpath_info.data_demo = select_data.data_demo;
            spider_state.list_page_xpath.push(xpath_info);
            return {
                xpath_info: xpath_info,
                spider_state: spider_state,
                listView: false}
        });

prevState为旧的state,后面的return里的内容是新的。

posted @ 2020-08-05 14:39  公众号python学习开发  阅读(317)  评论(0编辑  收藏  举报