footer-nav.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="footer-nav">
  3. <span
  4. v-if="leftNav"
  5. class="footer-nav-link footer-nav-left"
  6. @click="handleNavClick('prev')">
  7. <i class="el-icon-arrow-left"></i>
  8. {{ leftNav.title || leftNav.name }}
  9. </span>
  10. <span
  11. v-if="rightNav"
  12. class="footer-nav-link footer-nav-right"
  13. @click="handleNavClick('next')">
  14. {{ rightNav.title || rightNav.name }}
  15. <i class="el-icon-arrow-right"></i>
  16. </span>
  17. </div>
  18. </template>
  19. <style>
  20. .footer-nav {
  21. padding: 24px 0;
  22. color: #99a9bf;
  23. font-size: 14px;
  24. &::after {
  25. content: '';
  26. display: block;
  27. clear: both;
  28. }
  29. & i {
  30. transition: .3s;
  31. color: #d9def1;
  32. vertical-align: baseline;
  33. }
  34. }
  35. .footer-nav-link {
  36. cursor: pointer;
  37. transition: .3s;
  38. &:hover {
  39. color: #5e6d82;
  40. & i {
  41. color: #5e6d82;
  42. }
  43. }
  44. }
  45. .footer-nav-left {
  46. float: left;
  47. }
  48. .footer-nav-right {
  49. float: right;
  50. }
  51. </style>
  52. <script>
  53. import navConfig from '../nav.config.json';
  54. export default {
  55. data() {
  56. return {
  57. currentComponent: null,
  58. nav: [],
  59. currentIndex: -1,
  60. leftNav: null,
  61. rightNav: null
  62. };
  63. },
  64. watch: {
  65. '$route.path'() {
  66. this.updateNav();
  67. }
  68. },
  69. methods: {
  70. updateNav() {
  71. this.currentComponent = '/' + this.$route.path.split('/')[2];
  72. for (let i = 0, len = this.nav.length; i < len; i++) {
  73. if (this.nav[i].path === this.currentComponent) {
  74. this.currentIndex = i;
  75. break;
  76. }
  77. }
  78. this.leftNav = this.nav[this.currentIndex - 1];
  79. this.rightNav = this.nav[this.currentIndex + 1];
  80. },
  81. handleNavClick(direction) {
  82. this.$router.push(`/component${ direction === 'prev' ? this.leftNav.path : this.rightNav.path }`);
  83. }
  84. },
  85. created() {
  86. this.nav = navConfig[0].children.concat(navConfig[1]);
  87. navConfig[2].groups.map(group => group.list).forEach(list => {
  88. this.nav = this.nav.concat(list);
  89. });
  90. this.updateNav();
  91. }
  92. };
  93. </script>