当前位置:首页 > 前端 > Vue.js

Vue router的keep-alive include无效

问题描述和原因分析:

  今天调试Vue页面Router keep-alive路由保持页面的时候,发现include设置了,页面也不能被正常保持状态。开始怀疑是页面且套了vue components标签造成的,经过多重方式调试,发现都不是,罪归祸首是name,是name属性!!!注意一定要给需要缓存的页面组件都写name属性的值,不是路由Router 的name。

demo参考:

  1. <template>
  2. <keep-alive :include="include">
  3. <router-view id="app" />
  4. </keep-alive>
  5. </template>
  6. <script>
  7. export default {
  8. data () {
  9. return {
  10. include: 'message,home' // 需要被缓存部分页面的name(是组件的name,不是Router 的name)
  11. }
  12. }
  13. }
  14. </script>
读后有收获可以支付宝请作者喝咖啡
< 上一篇 下一篇 >
文章评论
评论功能改造中...
湘ICP备15005320号-1 似懂非懂 Powered by doyo. 网站地图
返回顶部