如果将 keep-alive 指定为 router-view ,如下所示
<keep-alive>
<router-view></router-view>
</keep-alive>
那么当重新访问该路由时,所有路由都会被有效地缓存并重新加载。
我希望能够在各个路线上指定保持活动选项。
如果有很多路由,并且只有 1 或 2 个需要保持活动状态而不重新渲染,那么缓存所有路由都是无用的
有什么方法可以做到这一点或有任何可用的解决方法
https://jsfiddle.net/Linusborg/L613xva0/4/ https://jsfiddle.net/Linusborg/L613xva0/4/
Vue 2.1.0 版本中的新增功能include
and exclude
用于有条件缓存组件的道具。注意使用name
option.
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)]
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)