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

Tags View如何禁止自动刷新? #304

Open
MyPuppet opened this issue Jun 3, 2021 · 3 comments
Open

Tags View如何禁止自动刷新? #304

MyPuppet opened this issue Jun 3, 2021 · 3 comments

Comments

@MyPuppet
Copy link

MyPuppet commented Jun 3, 2021

例如当我访问了<搜索订单>点击订单详情后进入新的tag<订单详情>页面,
如果此时我再从tag views列表重新回到<搜索订单>页面时所有搜索数据将丢失,我不得不重新搜索。

请问除了自己做缓存外有无更直接的方法解决此问题?

已经尝试过meta.noCache设置为false,但是这并没有解决问题,甚至没发现区别。。

@MyPuppet
Copy link
Author

MyPuppet commented Jun 3, 2021

我尝试使用了keep-alive,但是它并未生效,每次进入<搜索订单>时还是会自动刷新页面

@diudiudiuu
Copy link

一般用vuex记住上次访问数据。不过要考虑刷新数据丢失问题。

@diudiudiuu
Copy link

created () {

// 在页面加载时读取sessionStorage里的状态信息
if (sessionStorage.getItem('temporary')) {
  this.$store.state.session = JSON.parse(sessionStorage.getItem('temporary'))
  // 删除
  sessionStorage.removeItem('temporary')
}
const session = this.$store.state.session
// 在页面刷新时将vuex里的信息保存到sessionStorage里
window.addEventListener('beforeunload', () => {
  sessionStorage.setItem('temporary', JSON.stringify(session))
})

},

这块的代码写在App.vue中
1.创建store session 模块,这个模块可以专门保存刷新后需要保留的数据,比如,你的需求搜索信息,分页等.
2.只需要在页面上读取信息时,先读取store 中session的数据,这样应该可以保持住你上次的选择.
3.保持上次的选择但是接口还是会加载,不过应该可以满足你搜索不丢失问题

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

2 participants