1
1
<script setup lang="ts">
2
2
import { ref , onMounted } from ' vue'
3
3
import { tr } from ' ../../i18n'
4
+ import Loading from ' ./Loading.vue'
4
5
5
6
const props = defineProps ({
6
7
path: {
@@ -15,6 +16,7 @@ const props = defineProps({
15
16
})
16
17
17
18
const meta = ref <any >(null )
19
+ const loading = ref (false )
18
20
19
21
const t = (key : string ) => {
20
22
return tr (props .locale , ` api.${key } ` )
@@ -23,93 +25,100 @@ const t = (key :string) => {
23
25
onMounted (async () => {
24
26
const componentDocRoot = props .locale === ' en'
25
27
? ` /data/api `
26
- : ` /data/api/${props .locale } ` ;
28
+ : ` /data/api/${props .locale } `
27
29
try {
28
30
const jsonPath = ` ${componentDocRoot }/${props .path }.json?raw `
31
+
32
+ loading .value = true ;
29
33
const response = await fetch (jsonPath )
30
34
if (! response .ok ) {
31
35
throw new Error (` HTTP error! Status: ${response .status } ` )
32
36
}
33
37
meta .value = await response .json ()
38
+ loading .value = false
34
39
} catch (err ) {
40
+ loading .value = false
35
41
console .error (' Failed to load API data:' , err )
36
42
}
37
43
})
38
44
</script >
39
45
40
46
<template >
41
47
<section class =" component-doc" >
42
- <div class =" name" >
43
- {{ meta?.description }}
44
- </div >
45
- <PluginTabs >
46
- <PluginTabsTab :label =" t('props')" v-if =" meta?.props" >
47
- <div v-for =" (prop, index) in meta.props" :key =" index" class =" item" >
48
- <div class =" item-main" >
49
- <div >
50
- <code >{{ prop.name }}</code >:
51
- <span class =" text-tips" >{{ prop.type?.name || '—' }}</span >
48
+ <loading v-if =" loading" />
49
+ <template v-else >
50
+ <div class =" name" >
51
+ {{ meta?.description }}
52
+ </div >
53
+ <PluginTabs >
54
+ <PluginTabsTab :label =" t('props')" v-if =" meta?.props" >
55
+ <div v-for =" (prop, index) in meta.props" :key =" index" class =" item" >
56
+ <div class =" item-main" >
57
+ <div >
58
+ <code >{{ prop.name }}</code >:
59
+ <span class =" text-tips" >{{ prop.type?.name || '—' }}</span >
60
+ </div >
61
+ <div class =" default-value" >
62
+ <code >{{ prop.defaultValue?.value || '—' }}</code >
63
+ </div >
52
64
</div >
53
- <div class =" default-value" >
54
- <code >{{ prop.defaultValue?.value || '—' }}</code >
65
+ <div class =" description text-tips" v-if =" prop.description" >
66
+ <div class =" text-tip" >{{ t('description') }}</div >
67
+ <div class =" text-info" >{{ prop.description }}</div >
55
68
</div >
56
69
</div >
57
- <div class =" description text-tips" v-if =" prop.description" >
58
- <div class =" text-tip" >{{ t('description') }}</div >
59
- <div class =" text-info" >{{ prop.description }}</div >
60
- </div >
61
- </div >
62
- </PluginTabsTab >
63
- <PluginTabsTab :label =" t('events')" v-if =" meta?.events" >
64
- <div v-for =" (item, index) in meta.events" :key =" index" class =" item" >
65
- <div class =" item-main" >
66
- <div >
67
- <code >{{ item.name }}</code >:
68
- <span class =" text-tips" >({{ item.type?.names.join(',') || '—' }}) => void</span >
70
+ </PluginTabsTab >
71
+ <PluginTabsTab :label =" t('events')" v-if =" meta?.events" >
72
+ <div v-for =" (item, index) in meta.events" :key =" index" class =" item" >
73
+ <div class =" item-main" >
74
+ <div >
75
+ <code >{{ item.name }}</code >:
76
+ <span class =" text-tips" >({{ item.type?.names.join(',') || '—' }}) => void</span >
77
+ </div >
69
78
</div >
70
- </div >
71
- <div class =" description text-tips" v-if =" item.description" >
72
- <div class =" text-tip" >{{ t('description') }}</div >
73
- <div class =" text-info" >{{ item.description }}</div >
74
- </div >
75
- </div >
76
- </PluginTabsTab >
77
- <PluginTabsTab :label =" t('slots')" v-if =" meta?.slots" >
78
- <div v-for =" (item, index) in meta.slots" :key =" index" class =" item" >
79
- <div class =" item-main" >
80
- <div >
81
- <code >{{ item.name }}</code >
79
+ <div class =" description text-tips" v-if =" item.description" >
80
+ <div class =" text-tip" >{{ t('description') }}</div >
81
+ <div class =" text-info" >{{ item.description }}</div >
82
82
</div >
83
83
</div >
84
- <div class =" description text-tips" v-if =" item.description" >
85
- <div class =" text-tip" >{{ t('description') }}</div >
86
- <div class =" text-info" >{{ item.description }}</div >
84
+ </PluginTabsTab >
85
+ <PluginTabsTab :label =" t('slots')" v-if =" meta?.slots" >
86
+ <div v-for =" (item, index) in meta.slots" :key =" index" class =" item" >
87
+ <div class =" item-main" >
88
+ <div >
89
+ <code >{{ item.name }}</code >
90
+ </div >
91
+ </div >
92
+ <div class =" description text-tips" v-if =" item.description" >
93
+ <div class =" text-tip" >{{ t('description') }}</div >
94
+ <div class =" text-info" >{{ item.description }}</div >
95
+ </div >
87
96
</div >
88
- </div >
89
- </PluginTabsTab >
90
- <PluginTabsTab :label =" t('expose')" v-if =" meta?.expose" >
91
- <div v-for =" (item, index) in meta.expose" :key =" index" class =" item" >
92
- <div class =" item-main" >
93
- <div >
94
- <code >{{ item.name }}</code >
95
- <template v-if =" item .tags ?.length " >
96
- :
97
- <span class =" text-tips" >
97
+ </PluginTabsTab >
98
+ <PluginTabsTab :label =" t('expose')" v-if =" meta?.expose" >
99
+ <div v-for =" (item, index) in meta.expose" :key =" index" class =" item" >
100
+ <div class =" item-main" >
101
+ <div >
102
+ <code >{{ item.name }}</code >
103
+ <template v-if =" item .tags ?.length " >
104
+ :
105
+ <span class =" text-tips" >
98
106
({{ item.tags.map((e: any) => e.name).join(',') || '—' }}) => void
99
107
</span >
100
- </template >
108
+ </template >
109
+ </div >
110
+ </div >
111
+ <div class =" description text-tips" v-if =" item.description" >
112
+ <div class =" text-tip" >{{ t('description') }}</div >
113
+ <div class =" text-info" v-html =" item.description" />
101
114
</div >
102
115
</div >
103
- <div class =" description text-tips" v-if =" item.description" >
104
- <div class =" text-tip" >{{ t('description') }}</div >
105
- <div class =" text-info" v-html =" item.description" />
106
- </div >
107
- </div >
108
- </PluginTabsTab >
109
- </PluginTabs >
110
- <div class =" name" >
111
- <a :href =" meta?.sourceFiles[0]" target =" _blank" >{{ t('viewSource') }}</a >
112
- </div >
116
+ </PluginTabsTab >
117
+ </PluginTabs >
118
+ <div class =" name" >
119
+ <a :href =" meta?.sourceFiles[0]" target =" _blank" >{{ t('viewSource') }}</a >
120
+ </div >
121
+ </template >
113
122
</section >
114
123
</template >
115
124
0 commit comments