Movatterモバイル変換


[0]ホーム

URL:


NuxtLabs is joining Vercel
Read the announcement

ErrorPRO

GitHub
A pre-built error component with NuxtError support.

Usage

Like theMain component, the Error component renders a<main> element that works together with theHeader component to create a full-height layout that extends to the viewport's available height.

The Header component defines its height through a--ui-header-height CSS variable, which you can customize by overriding it in your CSS:
:root {  --ui-header-height: --spacing(16);}

Error

Use theerror prop to display an error message.

In most cases, you will receive theerror prop in yourerror.vue file.

404

Page not found

The page you are looking for does not exist.

<template>  <UError    :error="{      statusCode: 404,      statusMessage: 'Page not found',      message: 'The page you are looking for does not exist.'    }"  /></template>

Clear

Use theclear prop to customize or hide the clear button (withfalse value).

You can pass any property from theButton component to customize it.

404

Page not found

The page you are looking for does not exist.

<template>  <UError    :clear="{      color: 'neutral',      size: 'xl',      icon: 'i-lucide-arrow-left',      class: 'rounded-full'    }"    :error="{      statusCode: 404,      statusMessage: 'Page not found',      message: 'The page you are looking for does not exist.'    }"  /></template>

Redirect

Use theredirect prop to redirect the user to a different page when the clear button is clicked. Defaults to/.

404

Page not found

The page you are looking for does not exist.

<template>  <UError    redirect="/getting-started"    :error="{      statusCode: 404,      statusMessage: 'Page not found',      message: 'The page you are looking for does not exist.'    }"  /></template>

Examples

Withinerror.vue

Use the Error component in yourerror.vue:

error.vue
<script setup lang="ts">import type { NuxtError } from '#app'const props= defineProps<{  error: NuxtError}>()</script><template>  <UApp>    <UHeader />    <UError :error="error" />    <UFooter />  </UApp></template>
You might want to replicate the code of yourapp.vue inside yourerror.vue file to have the same layout and features, here is an example:https://github.com/nuxt/ui/blob/v3/docs/app/error.vue
You can read more about how to handle errors in theNuxt documentation, but when usingnuxt generate it is recommended to addfatal: true inside yourcreateError call to make sure the error page is displayed:
pages/[...slug].vue
<script setup lang="ts">const route= useRoute()const { data: page} = await useAsyncData(route.path, () => queryContent(route.path).findOne())if (!page.value){  throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })}</script>

API

Props

Prop Default Type
as

'main'

any

The element or component this component should render as.

error

Partial<NuxtError<unknown> & { message: string; }>

redirect

'/'

string

The URL to redirect to when the error is cleared.

clear

true

boolean | Partial<ButtonProps>

Display a button to clear the error in the links slot.{ size: 'lg', color: 'primary', variant: 'solid', label: 'Back to home' }

ui

{ root?: ClassNameValue; statusCode?: ClassNameValue; statusMessage?: ClassNameValue; message?: ClassNameValue; links?: ClassNameValue; }

Slots

Slot Type
default

{}

statusCode

{}

statusMessage

{}

message

{}

links

{}

Theme

app.config.ts
export default defineAppConfig({  uiPro: {    error: {      slots: {        root: 'min-h-[calc(100vh-var(--ui-header-height))] flex flex-col items-center justify-center text-center',        statusCode: 'text-base font-semibold text-primary',        statusMessage: 'mt-2 text-4xl sm:text-5xl font-bold text-highlighted text-balance',        message: 'mt-4 text-lg text-muted text-balance',        links: 'mt-8 flex items-center justify-center gap-6'      }    }  }})
vite.config.ts
import { defineConfig } from 'vite'import vuefrom '@vitejs/plugin-vue'import uifrom '@nuxt/ui/vite'export default defineConfig({  plugins: [    vue(),    ui({      uiPro: {        error: {          slots: {            root: 'min-h-[calc(100vh-var(--ui-header-height))] flex flex-col items-center justify-center text-center',            statusCode: 'text-base font-semibold text-primary',            statusMessage: 'mt-2 text-4xl sm:text-5xl font-bold text-highlighted text-balance',            message: 'mt-4 text-lg text-muted text-balance',            links: 'mt-8 flex items-center justify-center gap-6'          }        }      }    })  ]})
vite.config.ts
import { defineConfig } from 'vite'import vuefrom '@vitejs/plugin-vue'import uiProfrom '@nuxt/ui-pro/vite'export default defineConfig({  plugins: [    vue(),    uiPro({      uiPro: {        error: {          slots: {            root: 'min-h-[calc(100vh-var(--ui-header-height))] flex flex-col items-center justify-center text-center',            statusCode: 'text-base font-semibold text-primary',            statusMessage: 'mt-2 text-4xl sm:text-5xl font-bold text-highlighted text-balance',            message: 'mt-4 text-lg text-muted text-balance',            links: 'mt-8 flex items-center justify-center gap-6'          }        }      }    })  ]})

[8]ページ先頭

©2009-2025 Movatter.jp