如果 keep-alive 指定给 router-view 如下所示
<keep-alive>
<router-view></router-view>
</keep-alive>
然后所有路由都被有效缓存并在重新访问该路由时重新加载。
我希望能够在各个路由上指定保持事件状态的选项。
有很多路由,只有 1 或 2 个需要保持事件状态而无需重新渲染缓存所有路由是无用的
是否有任何方法或任何可用的解决方法
最佳答案
https://jsfiddle.net/Linusborg/L613xva0/4/
Vue 版本 2.1.0 中的新功能,用于有条件地缓存组件的 include
和 exclude
Prop 。请注意 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)]
}
}
}
关于vue.js - Keep-alive 在单个路由上而不是路由器 View 中的所有路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43116616/