Link
Bearbeiten
Die Link-Komponente ist ein Wrapper um <NuxtLink> mit dem custom prop.
inactive-classprop um eine Klasse zu setzen, wenn der Link inaktiv ist, wirdactive-classverwendet, wenn er aktiv ist.exactunterstützt das Styling mitactive-class, wenn der Link aktiv ist und die Route genau der aktuellen Route entspricht.exact-queryundexact-hashwerden mitactive-classformatiert, wenn der Link aktiv ist und die Abfrage oder der Hash genau mit der aktuellen Abfrage oder dem aktuellen Hash übereinstimmt.- Verwenden Sie
exact-query="partial"zum Formatieren mitactive-class, wenn der Link aktiv ist und die Abfrage teilweise mit der aktuellen Abfrage übereinstimmt.
- Verwenden Sie
Der Anreiz dahinter ist, die gleiche API wie NuxtLink wieder in Nuxt 2/Vue 2 bereitzustellen. Sie können mehr darüber in der Vue Router migration von Vue 2 Anleitung lesen.
Breadcrumb, Button, [ContextMenu](](/docs/components/context-menu), DropdownMenu und [NavigationMenuxph0505505xxph0555555xph0555x verwendet.xp053xTag
Die Link-Komponenten rendern ein <a>-Tag, wenn eine to-Prop bereitgestellt wird, andernfalls rendert sie ein <button>-Tag.
<template>
<ULink as="button">Link</ULink>
</template>to-Prop ändern.Style (Englisch)
Standardmäßig hat der Link standardmäßig aktive und inaktive Styles, siehe Abschnitt #theme.
<template>
<ULink to="/docs/components/link">Link</ULink>
</template>to-Prop zu ändern, um die aktiven und inaktiven Zustände zu sehen.Sie können dieses Verhalten mit der raw-Prop überschreiben und Ihre eigenen Styles mit class, active-class und inactive-class bereitstellen.
<template>
<ULink raw to="/docs/components/link" active-class="font-bold" inactive-class="text-muted">Link</ULink>
</template>active-class-und inactive-class-Props erhalten möchten, können Sie die folgenden Einstellungen zu Ihrem .vscode/settings.json hinzufügen:{
"tailwindCSS.classAttributes": [
"active-class",
"inactive-class"
]
}
Locale: badge{label="4.7+" class="align-text-top"}
Die Link-Komponente integriert sich automatisch in @nuxtjs/i18n, wenn sie installiert ist. Interne Links werden automatisch mit dem $localePath-Helfer lokalisiert, ohne dass ein manuelles Wrapping erforderlich ist.
<template>
<!-- Automatically becomes /en/about or /fr/about based on current locale -->
<ULink to="/about">About</ULink>
</template>
localePath() oder localeRoute() verwenden.API ist
Props (nicht)
| Prop | Default | Type |
|---|---|---|
as | 'button' | anyThe element or component this component should render as when not a link. |
type | 'button' | "reset" | "submit" | "button"The type of the button when not a link. |
disabled | boolean | |
active | undefined | boolean Force the link to be active independent of the current route. |
exact | boolean Will only be active if the current route is an exact match. | |
exactQuery | boolean | "partial" Allows controlling how the current route query sets the link as active. | |
exactHash | boolean Will only be active if the current route hash is an exact match. | |
inactiveClass | stringThe class to apply when the link is inactive. | |
raw | boolean When | |
locale | undefined | string | false | trueControl i18n auto-localization when
|
to | string | it | etRoute Location the link should navigate to when clicked on. | |
href | string | it | etAn alias for | |
external | boolean Forces the link to be considered as external (true) or internal (false). This is helpful to handle edge-cases | |
target | null | string | "_blank" | "_parent" | "_self" | "_top"Where to display the linked URL, as the name for a browsing context. | |
rel | null | "noopener" | "noreferrer" | "nofollow" | "sponsored" | "ugc" | stringA rel attribute value to apply on the link. Defaults to "noopener noreferrer" for external links. | |
noRel | boolean If set to true, no rel attribute will be added to the link | |
prefetchedClass | stringA class to apply to links that have been prefetched. | |
prefetch | boolean When enabled will prefetch middleware, layouts and payloads of links in the viewport. | |
prefetchOn | "visibility" | "interaction" | Partial<{ visibility: boolean; interaction: boolean; }>Allows controlling when to prefetch links. By default, prefetch is triggered only on visibility. | |
noPrefetch | boolean Escape hatch to disable | |
trailingSlash | "remove" | "append"An option to either add or remove trailing slashes in the | |
activeClass | stringClass to apply when the link is active | |
exactActiveClass | stringClass to apply when the link is exact active | |
ariaCurrentValue | 'page' | "step" | "page" | "true" | "false" | "location" | "date" | "time"Value passed to the attribute |
viewTransition | boolean Pass the returned promise of | |
replace | boolean Calls | |
name | string | |
autofocus | false | true | "true" | "false" | |
form | string | |
formaction | string | |
formenctype | string | |
formmethod | string | |
formnovalidate | false | true | "true" | "false" | |
formtarget | string | |
referrerpolicy | "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | |
download | any | |
hreflang | string | |
media | string | |
ping | string |
Slots (englisch)
| Slot | Type |
|---|---|
default | { active: boolean; } |
Theme Bearbeiten
export default defineAppConfig({
ui: {
link: {
base: 'outline-primary/25 focus-visible:outline-3 rounded-md',
variants: {
active: {
true: 'text-primary',
false: 'text-muted'
},
disabled: {
true: 'cursor-not-allowed opacity-75'
}
},
compoundVariants: [
{
active: false,
disabled: false,
class: [
'hover:text-default',
'transition-colors'
]
}
]
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
link: {
base: 'outline-primary/25 focus-visible:outline-3 rounded-md',
variants: {
active: {
true: 'text-primary',
false: 'text-muted'
},
disabled: {
true: 'cursor-not-allowed opacity-75'
}
},
compoundVariants: [
{
active: false,
disabled: false,
class: [
'hover:text-default',
'transition-colors'
]
}
]
}
}
})
]
})