Static GitHub Issues

[1706] About how to use keep-alive in Nuxt.js

prev: Can not access env variables from plugin
next: The error in basic.generate.test/validate

Fisrtly, Forgive my English is not very good.

I use keep-alive tag in default.vue, but it doesn't work. default.vue:

<template>
  <div>
    <keep-alive>
      <nuxt></nuxt>
    </keep-alive>
  </div>
</template>

At last, I find it can work after add a code in nuxt-child.js line65. nuxt/lib/app/components/nuxt-child.js:

return h('transition', {
    props: transitionProps,
    on: listeners
  }, [
  h('keep-alive', [
    h('router-view', data)
  ])
])

You can judge keep-alive based on the configuration of nuxt.config.js. result image

If you doesn't need keep-alive, you can add deactivated in this components.

deactivated () {
 this.$destroy()
},
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1531">#c1531</a>)</em></sub></div>