Components

<NuxtLinkLocale>

用于使用 localePath 的 <NuxtLink> 的简写组件

该组件基于 <NuxtLink> 构建,但通过内部使用 localePath() 更改了默认行为,以便更轻松地链接到本地化路由。

Props

除了下面描述的 props,该组件还支持所有 <NuxtLink> 文档记录的 props

Prop描述
locale可选 prop,强制使用传入的语言环境进行本地化,默认为当前语言环境。与 localePath()locale 参数相同

示例

基本用法

<template>
  <NuxtLinkLocale to="/">{{ $t('home') }}</NuxtLinkLocale>
</template>

<!-- 等效于 -->

<script setup>
const localePath = useLocalePath()
</script>

<template>
  <NuxtLink :to="localePath('/')">{{ $t('home') }}</NuxtLink>
</template>

强制语言环境解析

<template>
  <NuxtLinkLocale to="/" locale="nl">{{ $t('home') }}</NuxtLinkLocale>
</template>

<!-- 等效于 -->

<script setup>
const localePath = useLocalePath()
</script>

<template>
  <NuxtLink :to="localePath('/', 'nl')">{{ $t('home') }}</NuxtLink>
</template>