NavBar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="nav">
  3. <div class="nav-left">
  4. <div class="nav-item"
  5. :class="activeCode===item.code?'nav-active':''"
  6. v-for="(item,index) in navData"
  7. v-show="index<3 && item.noShow"
  8. @click="checkNav(item,index)"
  9. :key="'navC'+index"
  10. >
  11. <img :src="item.activeImg" v-if="activeCode===item.code" alt="">
  12. <img :src="item.img" v-else alt="">
  13. </div>
  14. </div>
  15. <div class="nav-right">
  16. <div class="nav-item"
  17. :class="activeCode===item.code?'nav-active':''"
  18. v-for="(item,index) in navData"
  19. v-show="index>=3 && item.noShow"
  20. @click="checkNav(item,index)"
  21. :key="'navR'+index"
  22. >
  23. <img :src="item.activeImg" v-if="activeCode===item.code" alt="">
  24. <img :src="item.img" v-else alt="">
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script lang="ts">
  30. import { defineComponent, onMounted, reactive, toRefs, watch } from 'vue'
  31. import { useRouter } from 'vue-router'
  32. export default defineComponent({
  33. props: {
  34. navList: {
  35. type: Array,
  36. default: () => []
  37. }
  38. },
  39. setup(props, contex) {
  40. const router = useRouter()
  41. const navData: any = []
  42. const proxyData = reactive({
  43. activeCode: 'air',
  44. navData: navData,
  45. setNavValue(val: any) {
  46. proxyData.navData = val
  47. },
  48. checkNav(item: any, index: any) {
  49. proxyData.activeCode = item.code
  50. contex.emit('changeNav', item)
  51. },
  52. setActiveCode(activeCode: any) {
  53. proxyData.activeCode = activeCode
  54. }
  55. })
  56. watch(
  57. props.navList, (newVal, oldValue) => {
  58. proxyData.setNavValue(newVal)
  59. }
  60. )
  61. onMounted(() => {
  62. proxyData.setNavValue(props.navList)
  63. })
  64. return {
  65. ...toRefs(proxyData)
  66. }
  67. }
  68. })
  69. </script>
  70. <style lang="scss" scoped>
  71. .nav {
  72. display: flex;
  73. justify-content: space-between;
  74. padding-left: 8px;
  75. padding-top: 8px;
  76. padding-bottom: 8px;
  77. padding-right: 16px;
  78. position: fixed;
  79. bottom: 30px;
  80. left: 50%;
  81. transform: translateX(-50%);
  82. height: 52px;
  83. width: 93%;
  84. background: #FFFFFF;
  85. box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.08);
  86. border-radius: 26px;
  87. z-index: 999;
  88. .nav-left, .nav-right {
  89. display: inline-block;
  90. vertical-align: middle;
  91. margin-right: 25px;
  92. .nav-item {
  93. position: relative;
  94. width: 36px;
  95. height: 36px;
  96. line-height: 36px;
  97. border-radius: 50%;
  98. display: inline-block;
  99. margin-right: 25px;
  100. text-align: center;
  101. vertical-align: middle;
  102. img {
  103. position: absolute;
  104. left: 50%;
  105. top: 50%;
  106. transform: translate(-50%, -50%);
  107. width: 23px;
  108. margin: 0 auto;
  109. //height: 23.5px;
  110. }
  111. }
  112. .nav-active {
  113. background: #FFE823;
  114. }
  115. }
  116. .nav-right {
  117. margin-right: 0;
  118. .nav-item {
  119. margin-right: 15px;
  120. }
  121. }
  122. }
  123. </style>