页脚定制
创建一个美观、功能完善的自定义页脚。
方式一:配置式页脚
在配置文件中设置:
ts
// .vitepress/config.mts
export default defineConfig({
themeConfig: {
footer: {
message: '基于 MIT 许可发布',
copyright: 'Copyright © 2026 VitePress 学习指南'
}
}
})1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
方式二:自定义页脚组件
vue
<!-- .vitepress/theme/components/CustomFooter.vue -->
<script setup lang="ts">
import { useData } from 'vitepress'
const { site } = useData()
const currentYear = new Date().getFullYear()
const links = {
learn: [
{ text: '指南', link: '/guide/' },
{ text: '教程', link: '/tutorial/' },
{ text: 'API 参考', link: '/reference/' }
],
resources: [
{ text: '案例展示', link: '/showcase' },
{ text: '视频教程', link: '/videos' },
{ text: '更新日志', link: '/changelog' }
],
community: [
{ text: 'GitHub', link: 'https://github.com/vuejs/vitepress' },
{ text: 'Discord', link: 'https://discord.gg/vue' },
{ text: 'Twitter', link: 'https://twitter.com/vuejs' }
]
}
</script>
<template>
<footer class="custom-footer">
<div class="footer-content">
<div class="footer-main">
<!-- Logo 和描述 -->
<div class="footer-brand">
<a href="/" class="logo">
<img src="/logo.svg" alt="Logo" />
<span>{{ site.title }}</span>
</a>
<p class="desc">{{ site.description }}</p>
</div>
<!-- 链接区域 -->
<div class="footer-links">
<div class="column">
<h4>学习</h4>
<ul>
<li v-for="item in links.learn" :key="item.link">
<a :href="item.link">{{ item.text }}</a>
</li>
</ul>
</div>
<div class="column">
<h4>资源</h4>
<ul>
<li v-for="item in links.resources" :key="item.link">
<a :href="item.link">{{ item.text }}</a>
</li>
</ul>
</div>
<div class="column">
<h4>社区</h4>
<ul>
<li v-for="item in links.community" :key="item.link">
<a :href="item.link" target="_blank">{{ item.text }}</a>
</li>
</ul>
</div>
</div>
</div>
<!-- 底部版权 -->
<div class="footer-bottom">
<p class="copyright">
Copyright © {{ currentYear }} {{ site.title }}
</p>
<p class="license">
基于 <a href="https://vitepress.dev" target="_blank">VitePress</a> 构建
</p>
</div>
</div>
</footer>
</template>
<style scoped>
.custom-footer {
background: var(--vp-c-bg-alt);
border-top: 1px solid var(--vp-c-divider);
padding: 3rem 0;
}
.footer-content {
max-width: 1200px;
margin: 0 auto;
padding: 0 24px;
}
.footer-main {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 4rem;
padding-bottom: 2rem;
border-bottom: 1px solid var(--vp-c-divider);
}
.footer-brand .logo {
display: flex;
align-items: center;
gap: 12px;
font-weight: 600;
font-size: 1.1rem;
text-decoration: none;
color: var(--vp-c-text-1);
margin-bottom: 1rem;
}
.footer-brand .logo img {
height: 32px;
}
.footer-brand .desc {
color: var(--vp-c-text-2);
font-size: 0.9rem;
line-height: 1.6;
}
.footer-links {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
}
.column h4 {
font-weight: 600;
margin-bottom: 1rem;
color: var(--vp-c-text-1);
}
.column ul {
list-style: none;
padding: 0;
}
.column li {
margin-bottom: 0.5rem;
}
.column a {
color: var(--vp-c-text-2);
text-decoration: none;
font-size: 0.9rem;
transition: color 0.2s;
}
.column a:hover {
color: var(--vp-c-brand-1);
}
.footer-bottom {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 2rem;
color: var(--vp-c-text-2);
font-size: 0.85rem;
}
.footer-bottom a {
color: var(--vp-c-brand-1);
text-decoration: none;
}
@media (max-width: 768px) {
.footer-main {
grid-template-columns: 1fr;
gap: 2rem;
}
.footer-links {
grid-template-columns: repeat(2, 1fr);
}
.footer-bottom {
flex-direction: column;
gap: 0.5rem;
text-align: center;
}
}
</style>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
方式三:备案信息页脚
vue
<script setup lang="ts">
interface Props {
icp?: string
policeNumber?: string
policeCode?: string
}
const props = defineProps<Props>()
</script>
<template>
<footer class="beian-footer">
<div class="links">
<a v-if="icp" href="https://beian.miit.gov.cn/" target="_blank">
{{ icp }}
</a>
<a
v-if="policeNumber && policeCode"
:href="`http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=${policeCode}`"
target="_blank"
>
<img src="/beian.png" alt="公安备案" />
{{ policeNumber }}
</a>
</div>
</footer>
</template>
<style scoped>
.beian-footer {
padding: 1rem;
text-align: center;
background: var(--vp-c-bg-alt);
border-top: 1px solid var(--vp-c-divider);
}
.links {
display: flex;
justify-content: center;
align-items: center;
gap: 1.5rem;
flex-wrap: wrap;
}
.links a {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: var(--vp-c-text-2);
text-decoration: none;
font-size: 0.85rem;
}
.links a:hover {
color: var(--vp-c-text-1);
}
.links img {
width: 16px;
height: 16px;
}
</style>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
注册到布局
ts
// .vitepress/theme/index.ts
import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import CustomFooter from './components/CustomFooter.vue'
export default {
extends: DefaultTheme,
Layout: () => {
return h(DefaultTheme.Layout, null, {
'doc-footer-before': () => h(CustomFooter)
})
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13