Search code examples
cachingvue.jsvuejs2vue-routerkeep-alive

How many components can be cached using Vue keep-alive?


I'm using keep-alive in the router-view like this:

<keep-alive>
  <router-view></router-view>
<keep-alive>

So I'm saving all "pages" of my app. My questions:

  • How many components can keep-alive save?

  • Can I program something to make keep-alive save just one component (the last one)?

Thanks in advance


Solution

  • I found a solution for my problem using the sugestion of @zizzo. I saved in the vuex the component that I wanted to save when I want to save (the last one). The code stayed like this:

    <keep-alive :include="[componentToKeepAlive.name]">
      <router-view></router-view>
    <keep-alive>
    
    
    ...mapGetters({
      componentToKeepAlive: 'global/componentToKeepAlive'
    })