Skip to content

Commit ef7f4cb

Browse files
committed
feat: Reusable Navbar Component (#63)
1 parent 8201254 commit ef7f4cb

File tree

15 files changed

+99
-136
lines changed

15 files changed

+99
-136
lines changed

src/App.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ onMounted(() => {
3333

3434
<template>
3535
<VanConfigProvider :theme="mode">
36+
<NavBar />
3637
<router-view v-slot="{ Component, route }">
3738
<transition :name="routeTransitionName">
3839
<div :key="route.name" class="app-wrapper">
@@ -45,11 +46,11 @@ onMounted(() => {
4546

4647
<style scoped>
4748
.app-wrapper {
48-
position: absolute;
49-
top: 0;
50-
left: 0;
5149
width: 100%;
5250
height: 100%;
51+
position: absolute;
52+
top: 46px;
53+
left: 0;
5354
overflow-y: auto;
5455
}
5556
</style>

src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export {}
88
declare module 'vue' {
99
export interface GlobalComponents {
1010
Chart: typeof import('./components/chart/index.vue')['default']
11-
Container: typeof import('./components/container/index.vue')['default']
11+
NavBar: typeof import('./components/NavBar.vue')['default']
1212
RouterLink: typeof import('vue-router')['RouterLink']
1313
RouterView: typeof import('vue-router')['RouterView']
1414
VanButton: typeof import('vant/es')['Button']

src/components/NavBar.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
const route = useRoute()
3+
const router = useRouter()
4+
5+
function onBack() {
6+
if (history.length > 1)
7+
history.back()
8+
else
9+
router.replace('/')
10+
}
11+
12+
const title = computed(() => {
13+
const { title } = (route.meta as { title?: string }) || {}
14+
return title || ''
15+
})
16+
</script>
17+
18+
<template>
19+
<VanNavBar
20+
v-show="title"
21+
:title="title"
22+
:fixed="true"
23+
left-arrow clickable
24+
@click-left="onBack"
25+
/>
26+
</template>

src/components/chart/typing.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/components/container/index.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/components/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/layouts/404.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ const router = useRouter()
1515
</div>
1616
</main>
1717
</template>
18-
19-
<style scoped>
20-
21-
</style>

src/layouts/default.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
2-
<main text="gray-700 dark:gray-200">
2+
<main p="16" text="gray-700 dark:gray-200">
33
<RouterView />
44

5-
<div mx-auto mt-15 text-center text-14 opacity-50>
5+
<div mx-auto py-15 text-center text-14 opacity-50>
66
Default Layout
77
</div>
88
</main>

src/layouts/home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<main py-20 text="gray-700 dark:gray-200">
2+
<main text="gray-700 dark:gray-200">
33
<RouterView />
44

55
<div mx-auto mt-15 text-center text-14 opacity-50>

src/pages/charts/index.vue

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ definePage({
33
name: 'charts',
44
meta: {
55
level: 2,
6+
title: '📊 Echarts 演示',
67
},
78
})
89
@@ -62,38 +63,12 @@ const scoreOption = {
6263
const refBarOption = ref(barOption)
6364
const refLineOption = ref(lineOption)
6465
const refScoreOption = ref(scoreOption)
65-
66-
// back
67-
const onClickLeft = () => history.back()
6866
</script>
6967

7068
<template>
7169
<div>
72-
<VanNavBar title="📊 Echarts" left-arrow fixed @click-left="onClickLeft" />
73-
74-
<Container>
75-
<div class="chart">
76-
<Chart :option="refBarOption" :style="{ height: '330px' }" />
77-
</div>
78-
79-
<div class="chart item">
80-
<Chart :option="refLineOption" :style="{ height: '330px' }" />
81-
</div>
82-
83-
<div class="chart item">
84-
<Chart :option="refScoreOption" :style="{ height: '330px' }" />
85-
</div>
86-
</Container>
70+
<Chart :option="refBarOption" :style="{ height: '330px' }" />
71+
<Chart :option="refLineOption" :style="{ height: '330px' }" />
72+
<Chart :option="refScoreOption" :style="{ height: '330px' }" />
8773
</div>
8874
</template>
89-
90-
<style lang="less" scoped>
91-
.chart {
92-
width: 100%;
93-
height: 300px;
94-
}
95-
96-
.chart.item {
97-
margin-top: 15px;
98-
}
99-
</style>

0 commit comments

Comments
 (0)