HeaderBar.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="header">
  3. <div class="container">
  4. <a href="">
  5. <div class="logo">
  6. <img src="../assets/images/logo.jpg"
  7. alt="">
  8. </div>
  9. </a>
  10. <div class="nav">
  11. <ul>
  12. <li :class="{'active': item.active}" v-for="item in navList" @click="select(item)">
  13. <div>{{item.name}}</div>
  14. </li>
  15. </ul>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. data () {
  23. return {
  24. navList: [{
  25. path: 'themeList',
  26. name: 'h5作品',
  27. active: false
  28. }, {
  29. path: 'spaList',
  30. name: '单页作品',
  31. active: false
  32. }, {
  33. path: 'about',
  34. name: '关于作者',
  35. active: false
  36. }
  37. ]
  38. }
  39. },
  40. methods: {
  41. select (item) {
  42. this.$router.push(item.path)
  43. }
  44. },
  45. mounted () {
  46. this.navList.forEach((element) => {
  47. if (element.path === this.$route.name) {
  48. element.active = true
  49. } else if (this.$route.name === 'index') {
  50. this.navList[0].active = true
  51. }
  52. })
  53. }
  54. }
  55. </script>
  56. <style lang="less">
  57. .header {
  58. width: 100%;
  59. height: 60px;
  60. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  61. background-color: #fff;
  62. }
  63. .header .container {
  64. margin: 0 auto;
  65. width: 1024px;
  66. text-align: center;
  67. }
  68. .header .logo img {
  69. float: left;
  70. height: 50px;
  71. }
  72. .header .nav {
  73. float: left;
  74. padding-left: 50px;
  75. }
  76. .header .nav li {
  77. float: left;
  78. width: 110px;
  79. line-height: 52px;
  80. border-top: solid 5px rgba(0, 0, 0, 0);
  81. text-align: center;
  82. list-style: none;
  83. }
  84. .header .nav li.active {
  85. border-top: solid 5px #0059f1;
  86. }
  87. .header .nav li div {
  88. height: 60px;
  89. font-size: 16px;
  90. color: #000;
  91. cursor: pointer;
  92. }
  93. .header .nav li.active div {
  94. color: #0059f1;
  95. }
  96. </style>