Home

Issue: 1706

About how to use keep-alive in Nuxt.js

[issue link]

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()
},
This question is available on Nuxt.js community (#c1531)