组件

<NuxtLinkLocale>

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

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

Props

此组件支持所有 <NuxtLink> 文档中描述的 props,并额外支持下面描述的 props。

属性说明
locale可选属性,用于强制使用传入的 Locale 进行本地化,默认为当前语言环境。与 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>