简体   繁体   English

如何在React中保存先前的组件DOM

[英]How to save previous component DOM in react

Root.js Root.js

const Root = () => (
    <HashRouter>
        <div>
            <Route exact path="/" component={Main}/>
            <Route path="/main/:page" component={Main}/>
            <Route path="/detail/:name" component={Detail}/>
        </div>
    </HashRouter>
);
export default Root;

Main in ItemList.js 主要在ItemList.js中

render() {
    let count = 0;
    return (
        <div>
            {this.state.data.map(function (data, i) {
                count++;
                return <Item data={data} key={count} order={count}/>;
            })}
        </div>
    );
}

Item is scroll bottom to(more view) append data( use ajax ) 项目滚动到(更多视图)追加数据(使用ajax)

Item Click to Link to={item idx} and go to detail page 项目单击链接到= {item idx}并转到详细信息页面

and back to page.. reset dom! 并返回页面..重置dom!

how to save dom?!? 如何保存dom?!?

Save the data somewhere, so when you back to index, load the data in the page. 将数据保存在某处,以便当您返回索引时,将数据加载到页面中。 Redux map help you to do all the things. Redux Map帮助您完成所有事情。 And remember react is a data-driven framework. 记住,react是一个数据驱动的框架。 You get the data, you have the view. 您获得了数据,便有了视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM