Save all routes on a single route in router mode

if keep-alive is indicated in the router view as shown below

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

then all routes are effectively cached and reloaded when this route is redefined.

I would like to specify the keep-alive option on separate routes.

With many routes, and only 1 or 2 that need to be kept alive without re-rendering, caching all routes is useless

is there any way to do this or any available workaround

+4
source share
1 answer

https://jsfiddle.net/Linusborg/L613xva0/4/

Vue 2.1.0, include exclude . name.

const Foo = {
    name: 'foo',
  template: '<div><p v-for="n in numbers">{{ n }}</p></div>',
  data: function() {
    return {
        numbers: [Math.round(Math.random() * 10), Math.round(Math.random() * 10)]
    }
  }
}

const Bar = {
    name: 'bar',
    template: '<div><p v-for="n in numbers"><strong>{{ n }}</strong></p></div>',
  data: function() {
    return {
        numbers: [Math.round(Math.random() * 10), Math.round(Math.random() * 10)]
    }
  }
}
+6

Source: https://habr.com/ru/post/1673599/


All Articles