navbar.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="stickyBox py-5">
  3. <div class="default-width d-flex align-center justify-space-between">
  4. <div class="header-link">
  5. <span class="cursor-pointer" :class="{'active-route' : isActive('/mall')}" @click="router.push('/mall')">首页</span>
  6. <span class="cursor-pointer mx-8" :class="{'active-route' : isActive('/mall/user', true)}" @click="router.push('/mall/user')">
  7. <v-icon>mdi-account-circle-outline</v-icon>
  8. 我的
  9. </span>
  10. <span class="cursor-pointer">
  11. <v-icon size="20">mdi-cart-outline</v-icon>
  12. 购物车
  13. </span>
  14. </div>
  15. <div class="search d-flex align-center">
  16. <v-text-field
  17. v-model="inputVal"
  18. placeholder="请输入关键词"
  19. color="primary"
  20. variant="plain"
  21. density="compact"
  22. clearable
  23. :hide-details="true"
  24. class="ml-3 px-2"
  25. style="height: 100%; line-height: 100%;"
  26. @keyup.enter="handleSearch"
  27. ></v-text-field>
  28. <v-btn class="searchBtn" prepend-icon="mdi-shopping-search-outline" @click="handleSearch">搜索</v-btn>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup>
  34. defineOptions({ name: 'formPage'})
  35. import { computed, ref } from 'vue'
  36. import { useRouter } from 'vue-router'
  37. const router = useRouter()
  38. const isActive = computed(() => (path, hasChild) => {
  39. const currentPath = router.currentRoute.value.path
  40. return hasChild ? currentPath.includes(path) : currentPath === path
  41. })
  42. const inputVal = ref('')
  43. const handleSearch = () => {}
  44. </script>
  45. <style scoped lang="scss">
  46. .stickyBox {
  47. position: sticky;
  48. top: 48px;
  49. z-index: 999;
  50. background-color: #fff;
  51. }
  52. .active-route {
  53. position: relative;
  54. color: var(--v-primary-base);
  55. &::before {
  56. content: '';
  57. width: 100%;
  58. height: 3px;
  59. position: absolute;
  60. bottom: -8px;
  61. left: 0;
  62. background-color: var(--v-primary-base);
  63. }
  64. }
  65. .header-link span:hover {
  66. color: var(--v-primary-base);
  67. }
  68. .search {
  69. height: 50px;
  70. width: 350px;
  71. border: 2px solid var(--v-primary-base);
  72. border-radius: 5px;
  73. .searchBtn {
  74. width: 100px;
  75. height: 49px;
  76. line-height: 48px;
  77. text-align: center;
  78. font-size: 18px;
  79. color: #fff;
  80. background-color: var(--v-primary-base);
  81. cursor: pointer;
  82. }
  83. }
  84. </style>