Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

切换页面之后,如何在之前的页面中保留已加载的数据 #14

Open
cgfeel opened this issue May 30, 2016 · 3 comments
Open

Comments

@cgfeel
Copy link

cgfeel commented May 30, 2016

情况如下:
1.有A、B两个页面
2.A页面通过ajax传入数据进来
3.切换B页面(通过router来实现),再换回A页面,之前加载的AJAS数据没有了。请问怎么解决?

@progrape
Copy link
Owner

路由本身不会帮你保存数据,你可以用一个变量把ajax加载的数据保存起来,渲染 A 的时候先检查那个变量有没有数据,如果没有数据,就发请求去加载,然后渲染页面;如果有数据了就直接用。

@cgfeel
Copy link
Author

cgfeel commented May 31, 2016

@progrape 假如我记录了A页面数据,切换回到A页面的时候,我怎么记录之前滚动的位置呢?

否则用户每次切换都要从顶部开始看内容。。。。。。

@x-bean
Copy link

x-bean commented Jul 9, 2016

我的解决方案是:在t.$container.appendChild(a)之前加了这句话:t.$container.innerHTML='';直接清空之前的代码,虽然猥琐,也算是解决了问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants