本文最后更新于316 天前,其中的信息可能已经过时,如有错误请发送邮件到1986413837@qq.com
404页面的出现有这么几种可能 :
- 错误输入了页面地址
- 路由连接跳转时,某些路由已经不存在了,而程序员并没有正确处理
需要配置好路由
routes.js

path: '/:pathMatch(.*)'
- 这是一个通配符路由,会匹配所有未被其他路由匹配的路径
:pathMatch是动态参数名(.*)是正则表达式,表示”匹配任意字符零次或多次”- 相当于 Vue Router 2.x 中的
path: '*'(Vue Router 3/4 的写法)
404页面的设计可以发挥自己的创意 让其显得不太单调 下面的文章总结了40个好看的404页面
40 个信息丰富且有趣的 CSS 404 错误页面示例_系统错误页面 示例-CSDN博客
我比较喜欢其中的第一个页面 并将其转化为了Vue3的SFC写法 源码如下
<template>
<div class="body font-[Ajar]">
<div class="mars"></div>
<img
src="@/assets/404/404.svg"
class="logo-404"
>
<img
src="@/assets/404/meteor.svg"
class="meteor"
>
<p class="title ">Oh no!!</p>
<p class="subtitle font-[Ajar]">
啊o~ 您搜索的页面好像找不到了<br>请拨打 13562617577 她会帮你解决
</p>
<div align="center">
<a
class="btn-back"
href="/"
>返回首页</a>
</div>
<img
src="@/assets/404/astronaut.svg"
class="astronaut"
>
<img
src="@/assets/404/spaceship.svg"
class="spaceship"
>
</div>
</template>
<script setup>
</script>
<style lang="scss" scoped>
@keyframes floating {
from {
transform: translateY(0px);
}
65% {
transform: translateY(15px);
}
to {
transform: translateY(0px);
}
}
.body {
background-image: url("@/assets/404/star.svg"), linear-gradient(to bottom, #05007A, #4D007D);
height: 100vh;
margin: 0;
background-attachment: fixed;
overflow: hidden;
}
.mars {
left: 0;
right: 0;
bottom: 0;
position: absolute;
height: 27vmin;
background: url("@/assets/404/mars.svg") no-repeat bottom center;
background-size: cover;
}
.logo-404 {
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
top: 16vmin;
width: 30vmin;
}
@media (max-width: 480px) and (min-width: 320px) {
.logo-404 {
top: 45vmin;
}
}
.meteor {
position: absolute;
right: 2vmin;
top: 16vmin;
}
.title {
color: white;
font-family: "Nunito", sans-serif;
font-weight: 600;
text-align: center;
font-size: 5vmin;
margin-top: 31vmin;
}
@media (max-width: 480px) and (min-width: 320px) {
.title {
margin-top: 65vmin;
}
}
.subtitle {
color: white;
font-family: "Nunito", sans-serif;
font-weight: 400;
text-align: center;
font-size: 3.5vmin;
margin-top: 10vmin;
margin-bottom: 9vmin;
}
.btn-back {
border: 1px solid white;
color: white;
height: 5vmin;
padding: 12px;
font-family: "Nunito", sans-serif;
text-decoration: none;
border-radius: 5px;
}
.btn-back:hover {
background: white;
color: #4D007D;
}
@media (max-width: 480px) and (min-width: 320px) {
.btn-back {
font-size: 3.5vmin;
}
}
.astronaut {
position: absolute;
top: 18vmin;
left: 10vmin;
height: 30vmin;
animation: floating 3s infinite ease-in-out;
}
@media (max-width: 480px) and (min-width: 320px) {
.astronaut {
top: 2vmin;
}
}
.spaceship {
position: absolute;
bottom: 15vmin;
right: 24vmin;
}
@media (max-width: 480px) and (min-width: 320px) {
.spaceship {
width: 45vmin;
bottom: 18vmin;
}
}
</style>
其中会用到一些svg图片 放在下面的压缩包里了…………