RouteView.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="main">
  3. <keep-alive>
  4. <router-view v-if="keepAlive" />
  5. </keep-alive>
  6. <router-view v-if="!keepAlive" />
  7. </div>
  8. <!-- 以下注释是原始版本
  9. <template>
  10. <div class="main">
  11. <keep-alive :include="includedComponents">
  12. <router-view v-if="keepAlive" />
  13. </keep-alive>
  14. <router-view v-if="!keepAlive" />
  15. </div>
  16. </template>
  17. <script>
  18. import Vue from 'vue'
  19. import { CACHE_INCLUDED_ROUTES } from '@/store/mutation-types'
  20. export default {
  21. name: 'RouteView',
  22. computed: {
  23. // update-begin--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
  24. includedComponents() {
  25. const includedRouters = Vue.ls.get(CACHE_INCLUDED_ROUTES)
  26. console.log('includedRouters:' + includedRouters)
  27. // 如果是缓存路由,则加入到 cache_included_routes
  28. if (this.$route.meta.keepAlive && this.$route.meta.componentName) {
  29. let cacheRouterArray = Vue.ls.get(CACHE_INCLUDED_ROUTES) || []
  30. if (!cacheRouterArray.includes(this.$route.meta.componentName)) {
  31. cacheRouterArray.push(this.$route.meta.componentName)
  32. // cacheRouterArray.push("OnlCgformHeadList")
  33. console.log('Vue ls set componentName :' + this.$route.meta.componentName)
  34. Vue.ls.set(CACHE_INCLUDED_ROUTES, cacheRouterArray)
  35. console.log('Vue ls includedRouterArrays :' + Vue.ls.get(CACHE_INCLUDED_ROUTES))
  36. return cacheRouterArray
  37. }
  38. }
  39. return includedRouters
  40. },
  41. // update-end--Author:scott Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
  42. keepAlive () {
  43. return this.$route.meta.keepAlive
  44. }
  45. }
  46. }
  47. </script>
  48. 以上注释是原始版本 -->
  49. </template>
  50. <script>
  51. export default {
  52. name: 'RouteView',
  53. computed: {
  54. keepAlive () {
  55. return this.$route.meta.keepAlive
  56. }
  57. }
  58. }
  59. </script>