@@ -6,16 +6,15 @@ import { data } from '../plugins/CopyrightLoader.data'
6
6
7
7
const orgName = useData ().theme .value .org
8
8
9
- // 初始化需要更新的变量
10
- const attrs = ref <Record <string , any > | null >(null )
11
-
12
9
const route = useRoute () // 获取当前路由对象
13
10
14
- // 定义一个函数,基于当前路由路径更新数据
15
- function updateData() {
16
- const paths = route .path .replace (' .md' , ' ' ).split (' /' ).filter ((item : string ) => item !== ' ' )
17
- attrs .value = searchClosestInTrie (data , paths )
18
- }
11
+ const attrs = computed (() => {
12
+ const paths = route .path
13
+ .replace (' .md' , ' ' )
14
+ .split (' /' )
15
+ .filter ((item : string ) => item !== ' ' )
16
+ return searchClosestInTrie (data , paths )
17
+ })
19
18
20
19
function searchClosestInTrie(
21
20
that : Trie <Record <string , any >>,
@@ -25,7 +24,11 @@ function searchClosestInTrie(
25
24
if (path .length === 0 )
26
25
return node .value
27
26
if (path [0 ] in node .children ) {
28
- let value = searchClosestInTrie (that , path .slice (1 ), node .children [path [0 ]])
27
+ let value = searchClosestInTrie (
28
+ that ,
29
+ path .slice (1 ),
30
+ node .children [path [0 ]],
31
+ )
29
32
if (value === null )
30
33
value = node .value
31
34
return value
@@ -45,15 +48,6 @@ const authors = computed(() => {
45
48
const displayAuthors = computed (() => {
46
49
return ` ${authors .value .join (' , ' )} `
47
50
})
48
-
49
- // 监听页面路由变化,路由变化时更新数据
50
- watch (
51
- () => route .path ,
52
- () => {
53
- updateData () // 路由变化时调用更新逻辑
54
- },
55
- { immediate: true }, // 确保在初次加载时也能更新数据
56
- )
57
51
</script >
58
52
59
53
<template >
@@ -66,24 +60,35 @@ watch(
66
60
<span >这篇文章 </span >
67
61
<span >{{ `“${attrs!.title}”` }}</span >
68
62
<span > 由 </span >
69
- <a v-if =" attrs?.copyright?.url" :href =" attrs.copyright.url" >{{ displayAuthors }}</a >
63
+ <a v-if =" attrs?.copyright?.url" :href =" attrs.copyright.url" >{{
64
+ displayAuthors
65
+ }}</a >
70
66
<span v-else >{{ displayAuthors }}</span >
71
67
<span > 创作</span >
72
68
<span v-if =" attrs?.copyright?.org && attrs?.copyright?.license" >
73
69
,{{ attrs.copyright.org }} 在
74
- <a v-if =" attrs?.copyright?.licenseUrl" :href =" attrs.copyright.licenseUrl" >{{ attrs.copyright.license }}</a >
70
+ <a
71
+ v-if =" attrs?.copyright?.licenseUrl"
72
+ :href =" attrs.copyright.licenseUrl"
73
+ >{{ attrs.copyright.license }}</a >
75
74
<span v-else >{{ attrs.copyright.license }}</span >
76
75
许可下使用
77
76
</span >
78
77
<span v-else-if =" orgName && attrs?.copyright?.license" >
79
78
,{{ orgName }} 在
80
- <a v-if =" attrs?.copyright?.licenseUrl" :href =" attrs.copyright.licenseUrl" >{{ attrs.copyright.license }}</a >
79
+ <a
80
+ v-if =" attrs?.copyright?.licenseUrl"
81
+ :href =" attrs.copyright.licenseUrl"
82
+ >{{ attrs.copyright.license }}</a >
81
83
<span v-else >{{ attrs.copyright.license }}</span >
82
84
许可下使用
83
85
</span >
84
86
<span v-else-if =" attrs?.copyright?.license" >
85
87
,Project Trans 在
86
- <a v-if =" attrs?.copyright?.licenseUrl" :href =" attrs.copyright.licenseUrl" >{{ attrs.copyright.license }}</a >
88
+ <a
89
+ v-if =" attrs?.copyright?.licenseUrl"
90
+ :href =" attrs.copyright.licenseUrl"
91
+ >{{ attrs.copyright.license }}</a >
87
92
<span v-else >{{ attrs.copyright.license }}</span >
88
93
许可下使用
89
94
</span >
0 commit comments