File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1
1
<script setup>
2
2
import PageNotFound from ' ./PageNotFound.vue' ;
3
3
import { useRoute } from ' vue-router' ;
4
- import { shallowRef , defineAsyncComponent , watch } from ' vue' ;
4
+ import {
5
+ shallowRef ,
6
+ defineAsyncComponent ,
7
+ watch ,
8
+ useTemplateRef ,
9
+ computed
10
+ } from ' vue' ;
11
+ import CategorySecond from ' ./CategorySecond.vue' ;
5
12
6
13
const props = defineProps ({
7
14
articles: {
8
15
type: Object ,
9
16
required: true
10
17
},
11
- title: String ,
18
+ showTitle: {
19
+ type: Boolean ,
20
+ default: false
21
+ },
22
+ defaultTitle: String ,
12
23
pathPrefix: String ,
13
24
pathSuffix: String
14
25
});
@@ -17,6 +28,10 @@ const props = defineProps({
17
28
const route = useRoute ();
18
29
const loadError = shallowRef (false );
19
30
const articleComponent = shallowRef ();
31
+ const articleComponentRef = useTemplateRef (' articleComponentRef' );
32
+ const articleTitle = computed (
33
+ () => articleComponentRef .value ? .frontmatter .title
34
+ );
20
35
21
36
function loadArticle (slug ) {
22
37
const path = ` ${ props .pathPrefix ?? ' ./articles/' }${slug .split (' #' )[0 ]}${props .pathSuffix ?? ' .md' }` ;
@@ -44,7 +59,13 @@ watch(
44
59
<PageNotFound />
45
60
</template>
46
61
<template v-else>
47
- <component class="vuepress-markdown-body" :is="articleComponent" />
62
+ <CategorySecond
63
+ v-if="showTitle"
64
+ :title="articleTitle ?? defaultTitle" />
65
+ <component
66
+ ref="articleComponentRef"
67
+ class="vuepress-markdown-body"
68
+ :is="articleComponent" />
48
69
</template>
49
70
</div>
50
71
</template>
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const articles = import.meta.glob('./articles/*.zh.md');
7
7
<template >
8
8
<MarkdownDetail
9
9
:articles =" articles"
10
+ :show-title =" true"
10
11
default-title =" 众筹详情"
11
12
path-suffix =" .zh.md" />
12
13
</template >
You can’t perform that action at this time.
0 commit comments