Skip to content

指令

TranslationDirective

翻译指令(v-t

签名:

typescript
export type TranslationDirective<T = HTMLElement> = ObjectDirective<T>;

已弃用

将在 vue-i18n v12 中移除

详情

使用本地化消息更新元素的 textContent

您可以使用字符串语法或对象语法。

字符串语法可以指定为本地化消息的键路径。

如果您要使用对象语法,需要将以下参数指定为对象键:

- path: 必需,本地化消息的键
- locale: 可选,语言环境
- args: 可选,用于列表或命名格式化

示例

html
<!-- 字符串语法:字面量 -->
<p v-t="'foo.bar'"></p>

<!-- 字符串语法:通过数据或计算属性绑定 -->
<p v-t="msg"></p>

<!-- 对象语法:字面量 -->
<p v-t="{ path: 'hi', locale: 'ja', args: { name: 'kazupon' } }"></p>

<!-- 对象语法:通过数据或计算属性绑定 -->
<p v-t="{ path: greeting, args: { name: fullName } }"></p>