Header.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup lang="ts">
  2. const props = withDefaults(
  3. defineProps<{
  4. title: string
  5. showBack?: boolean
  6. }>(),
  7. {
  8. showBack: true,
  9. },
  10. )
  11. const emit = defineEmits<{
  12. (e: 'back'): void
  13. }>()
  14. const router = useRouter()
  15. const handleBack = () => {
  16. emit('back')
  17. router.back()
  18. }
  19. </script>
  20. <template>
  21. <header class="common-header">
  22. <button
  23. v-if="props.showBack"
  24. type="button"
  25. class="common-header__back"
  26. @click="handleBack"
  27. >
  28. <van-icon
  29. name="arrow-left"
  30. :size="18"
  31. />
  32. </button>
  33. <div
  34. v-else
  35. class="common-header__spacer"
  36. />
  37. <h1 class="common-header__title">
  38. {{ props.title }}
  39. </h1>
  40. <div class="common-header__spacer">
  41. <slot name="right" />
  42. </div>
  43. </header>
  44. </template>
  45. <style scoped lang="scss">
  46. .common-header {
  47. position: sticky;
  48. top: 0;
  49. z-index: 10;
  50. height: 44px;
  51. padding: 0 16px;
  52. display: flex;
  53. align-items: center;
  54. justify-content: space-between;
  55. background: #fff;
  56. }
  57. .common-header__back {
  58. border: none;
  59. padding: 4px;
  60. border-radius: 999px;
  61. background: transparent;
  62. display: flex;
  63. align-items: center;
  64. justify-content: center;
  65. }
  66. .common-header__title {
  67. font-size: 18px;
  68. font-weight: 500;
  69. color: #17171a;
  70. }
  71. .common-header__spacer {
  72. width: 24px;
  73. height: 24px;
  74. display: flex;
  75. align-items: center;
  76. justify-content: flex-end;
  77. }
  78. </style>