组件

<NuxtLinkLocale>

用于结合 <NuxtLink> 使用 localePath 的简化组件

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

Props

该组件支持所有 <NuxtLink> 中记录的 props,并增加了下面描述的 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>