index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div>
  3. <el-container>
  4. <el-aside v-if="showComponents" width="200px">
  5. <Sidebar />
  6. </el-aside>
  7. <el-container style="display: block;width:100%">
  8. <Navbar v-if="showComponents" />
  9. <app-main />
  10. </el-container>
  11. </el-container>
  12. </div>
  13. </template>
  14. <script>
  15. import Navbar from './components/Navbar.vue'
  16. import AppMain from './components/AppMain.vue'
  17. import Sidebar from './components/Sidebar/menu'
  18. export default {
  19. components: {
  20. Navbar,
  21. AppMain,
  22. Sidebar
  23. },
  24. data() {
  25. return {
  26. include: []
  27. }
  28. },
  29. computed: {
  30. // 是否显示顶部栏、菜单栏
  31. showComponents() {
  32. if (this.$route.path != '/') {
  33. return true
  34. } else {
  35. return false
  36. }
  37. }
  38. },
  39. watch: {
  40. $route(to, from) {
  41. if (to.meta.keepAlive) {
  42. !this.include.includes(to.name) && this.include.push(to.name)
  43. }
  44. if (to.meta.parentNode && to.meta.parentNode.indexOf(from.name) > -1) {
  45. !this.include.includes(from.name) && this.include.push(from.name)
  46. } else if (
  47. from.meta.parentNode &&
  48. from.meta.parentNode.indexOf(to.name) > -1
  49. ) {
  50. // console.log()
  51. } else {
  52. if (from.meta.parentNode) {
  53. let index = this.include.indexOf(from.meta.parentNode)
  54. index !== -1 && this.include.splice(index, 1)
  55. }
  56. if (!from.meta.parentNode) {
  57. let index = this.include.indexOf(from.name)
  58. index !== -1 && this.include.splice(index, 1)
  59. }
  60. }
  61. }
  62. }
  63. }
  64. </script>