NavBar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="top-bar">
  3. <div class="img">
  4. <img src="../../assets/img/logo.png" >
  5. </div>
  6. <div class="barbox">
  7. <div class="bar-item" v-for="( item, index ) in navList" :key="index" @click="navClick(item.path,index)" :class="{'action':currentUrl.indexOf(item.path) !=-1}">
  8. <div>{{item.title}}</div>
  9. <div class="xian" v-if="currentUrl.indexOf(item.path) !=-1"></div>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. navList: [
  19. {
  20. path: '/home',
  21. title: '首页',
  22. },
  23. {
  24. path: '/about',
  25. title: '关于我们',
  26. },
  27. {
  28. path: '/loveList',
  29. title: '案例展示',
  30. },
  31. {
  32. path: '/join',
  33. title: '新闻动态',
  34. },
  35. {
  36. path: '/donation',
  37. title: '节水测试',
  38. },
  39. {
  40. path: '/concat',
  41. title: '物联网登录',
  42. }
  43. ],
  44. currentIndex: 0
  45. };
  46. },
  47. computed: {
  48. currentUrl() {
  49. return this.$route.path
  50. }
  51. },
  52. methods: {
  53. navClick(url,index) {
  54. let currentUrl = this.$route.path
  55. console.log(url)
  56. console.log(currentUrl,"now")
  57. if(currentUrl === url) {
  58. return
  59. }else {
  60. console.log("1")
  61. this.currentIndex = index
  62. console.log(this.currentIndex)
  63. this.$router.push(url)
  64. }
  65. }
  66. }
  67. };
  68. </script>
  69. <style lang="scss" scoped>
  70. .top-bar {
  71. max-width: 1920px;
  72. min-width: 1080px;
  73. height: 140px;
  74. margin: 0 auto;
  75. padding: 15px;
  76. display: flex;
  77. justify-content: space-between;
  78. background-color: #FFFFFF;
  79. font-size: 18px;
  80. font-family: PingFang SC;
  81. font-weight: bold;
  82. color: #000000;
  83. letter-spacing:3px;
  84. margin-bottom: 24px;
  85. align-items:center;
  86. .img {
  87. width: 200px;
  88. height: auto;
  89. img {
  90. width: 100%;
  91. height: auto;
  92. }
  93. }
  94. .barbox {
  95. display: flex;
  96. .bar-item {
  97. margin-left: 30px;
  98. flex-grow: 1;
  99. align-items: center;
  100. font-family: PingFang SC;
  101. font-size: 18px;
  102. cursor:pointer;
  103. display: flex;
  104. flex-direction: column;
  105. align-items: center;
  106. }
  107. .xian {
  108. width: 110%;
  109. background: #0165B5;
  110. height: 3px;
  111. margin-top: 10px;
  112. }
  113. }
  114. .action {
  115. // background-color: #0165B5;
  116. color: #0165B5
  117. }
  118. }
  119. </style>