Nuxt.js: keep-alive not working, resets data after change tab

Created on 6 Mar 2019  路  5Comments  路  Source: nuxt/nuxt.js

Version

v2.4.5

Reproduction link

https://codesandbox.io/s/9z8p69427r

Steps to reproduce

  1. Click on ROEL USER button to go to Profile tab, which is an url (/roelmagdaleno/profile)
  2. Go to Posts or Payments tab, when the component renders for the first time, it will show you the data.
  3. Go back to Profile and then go to posts or payments again.
  4. The current data that should kept alive has been reset to the initial values, an empty array.

What is expected ?

Keep alive the current tab data, so it won't make another API call.

What is actually happening?

The data is reset when user change the tab and enter again.

This bug report is available on Nuxt community (#c8776)
bug-report

Most helpful comment

I don't think this issue should be closed. We don't know the root cause of this problem.
I am more inclined to think that this is a bug.

All 5 comments

https://codesandbox.io/s/73lqxj6436
posts.vue
image
when using keep-alive, data() will be called repeatedly when the component is activated.
I don't know if this is a bug.

Thank you, that works but I feel it is a little bit hacky.
In Vue.js, I could set the same behaviour without the if condition, weird.

Thanks!

I don't think this issue should be closed. We don't know the root cause of this problem.
I am more inclined to think that this is a bug.

Sorry, I closed since no one else commented, but you're right. Maybe someone of the core team could decide if it is a bug or not.

I'll have a look.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

gary149 picture gary149  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments