<template>
<div class="error-page">
<div class="error-icon">⚠️div>
<h1>{{ getErrorTitle() }}h1>
<p>{{ getErrorMessage() }}p>
<div class="actions">
<button @click="goBack">返回上页button>
<button @click="goHome">返回首页button>
<button @click="retry" v-if="canRetry">重试button>
div>
div>
template>
<script setup>
const error = useError();
const router = useRouter();
const getErrorTitle = () => {
const titles = {
404: '页面未找到',
403: '访问被拒绝',
500: '服务器错误',
502: '网关错误'
};
return titles[error.value?.statusCode] || '发生错误';
};
const getErrorMessage = () => {
const messages = {
404: '抱歉,您访问的页面不存在。',
403: '您没有权限访问此页面。',
500: '服务器遇到问题,请稍后重试。',
502: '网关暂时不可用,请稍后重试。'
};
return messages[error.value?.statusCode] || '发生了意外错误。';
};
const goBack = () => router.back();
const goHome = () => router.push('/');
const retry = () => window.location.reload();
const canRetry = computed(() => [500, 502].includes(error.value?.statusCode));
script>