Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude specific component from caching Using Nuxt.js keep-alive props?

Tags:

vue.js

nuxt.js

I have trouble with Nuxt.js keep-alive prop, I am trying to cache all components except one, and load dynamic data again. But all components are cached, I can't figure out what am I doing wrong. Is this the correct way to use keep-alive in Nuxt.js?

Default layout

<template>
  <div>
    <Nuxt keep-alive :keep-alive-props="{exclude: ['basket']}" />
  </div>
</template>

Inside basket

<template>
  <div>
    <h1>basket</h1>
    {{items}}
  </div>
</template>

<script>
export default {       
  async fetch() {
    let resp = await this.$axios.$get('api/items')
    this.items = resp.data
   },    
  fetchOnServer:false,
}
</script>

Vue devtools

enter image description here

like image 408
Nightcrawler Avatar asked Nov 15 '25 19:11

Nightcrawler


1 Answers

keep-alive only caches page components, so I'm assuming basket is a page.

The component name for pages is the relative path to the page. Assuming this directory structure:

pages/
 - index.vue
 - basket.vue

...the name for the basket page would be "pages/basket.vue":

<Nuxt keep-alive :keep-alive-props="{exclude: ['pages/basket.vue']}" />

demo

like image 97
tony19 Avatar answered Nov 17 '25 15:11

tony19



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!