【问题标题】:Keep-alive on a single route instaead of all routes in router-view在单个路由上保持活动,而不是路由器视图中的所有路由
【发布时间】:2017-08-24 07:19:09
【问题描述】:

如果keep-alive被指定给router-view如下

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

然后当重新访问该路由时,所有路由都会被有效地缓存和重新加载。

我希望能够在各个路由上指定保持活动选项。

有很多路由,只有 1 或 2 条需要保持活动,而无需重新渲染缓存所有路由是无用的

是否有任何方法或任何可用的解决方法

【问题讨论】:

标签: vue.js vuejs2 vue-component vue-router


【解决方案1】:

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

Vue 版本 2.1.0 中的新功能,includeexclude 属性用于有条件地缓存组件。请注意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)]
    }
  }
}

【讨论】:

  • 谢谢...可以提供这个包含和排除道具的文档链接吗...再次感谢您
猜你喜欢
  • 1970-01-01
  • 2020-01-21
  • 2018-03-24
  • 1970-01-01
  • 2017-10-22
  • 2018-12-09
  • 2021-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多