vue keep-alive include无效

原文链接: https://dsx2016.com/?p=713

微信公众号: 大师兄2016

检查版本

确定当前的vue版本的是2.1+

因为includeexcludevue2.1.0新增的两个属性.

package.json

"vue": "^2.5.2",

检查name

注意,不是router.js中的name,而是单个vue组件中的name属性.

建议将router.js中的namevue组件的name保持一致,不要混乱.

export default {
    name: "index"
}

多层嵌套

网上的答案几乎都是检查vue组件的name属性,但还是有一个巨坑.

那就是多级嵌套<router-view></router-view>,但凡有超过两个以上的router-view且是父子级关系,请都加上keep-alive,只加一个不会生效.

// app.vue
<keep-alive include="app,index">
   <router-view></router-view>
</keep-alive>
​
// other.vue
<keep-alive include="app,index">
   <router-view></router-view>
</keep-alive>
发布了121 篇原创文章 · 获赞 44 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/weixin_37865166/article/details/103249414