Skip to content

组件

BaseFormatProps

Vue I18n 提供的组件的基础格式属性

签名:

typescript
export interface BaseFormatProps

详情

组件(如 Translation、DatetimeFormat 和 NumberFormat)底层属性的接口定义。

i18n

签名:

typescript
i18n?: Composer;

详情

具有现有作用域的组合器实例。

此选项优先于 scope 选项。

locale

签名:

typescript
locale?: Locale;

详情

指定组件要使用的语言环境。

如果指定了该选项,则目标组件的全局作用域或父级作用域的语言环境不会被覆盖,而会使用指定的语言环境。

scope

签名:

typescript
scope?: ComponentI18nScope;

详情

指定目标组件要使用的作用域。

您可以指定 globalparent

如果指定为 global,则使用全局作用域;如果指定为 parent,则使用目标组件父级的作用域。

如果父级是全局作用域,则使用全局作用域;如果是局部作用域,则使用局部作用域。

tag

签名:

typescript
tag?: string | object;

详情

用于包装插槽中分发的内容。如果省略,则插槽内容被视为 Fragment。

您可以指定基于字符串的标签名称,例如 p,或者指定组件定义的对象。

DatetimeFormat

日期时间格式化组件

签名:

typescript
DatetimeFormat: {
    new (): {
        $props: VNodeProps & DatetimeFormatProps & BaseFormatProps;
    };
}

详情

有关属性的详细信息,请参见以下项目

DANGER

不支持 IE,因为 IE 不支持 Intl.DateTimeFormat#formatToParts

如果您想使用它,需要使用 polyfill

另请参阅

DatetimeFormatProps

日期时间格式化组件的属性

签名:

typescript
export type DatetimeFormatProps = FormattableProps<number | Date, Intl.DateTimeFormatOptions>;

FormattableProps

可格式化属性

签名:

typescript
export interface FormattableProps<Value, Format> extends BaseFormatProps

详情

在 DatetimeFormat 或 NumberFormat 组件中使用的属性

format

签名:

typescript
format?: string | Format;

详情

目标组件要使用的格式。

指定格式键字符串或由 ECMA 402 中定义的 Intl API 格式。

value

签名:

typescript
value: Value;

详情

为目标组件指定的值

NumberFormat

数字格式化组件

签名:

typescript
NumberFormat: {
    new (): {
        $props: VNodeProps & NumberFormatProps & BaseFormatProps;
    };
}

详情

有关属性的详细信息,请参见以下项目

DANGER

不支持 IE,因为 IE 不支持 Intl.NumberFormat#formatToParts

如果您想使用它,需要使用 polyfill

另请参阅

NumberFormatProps

数字格式化组件的属性

签名:

typescript
export type NumberFormatProps = FormattableProps<number, Intl.NumberFormatOptions>;

Translation

翻译组件

签名:

typescript
Translation: {
    new (): {
        $props: VNodeProps & TranslationProps;
    };
}

详情

有关属性的详细信息,请参见以下项目

另请参阅

示例

html
<div id="app">
  <!-- ... -->
  <i18n keypath="term" tag="label" for="tos">
    <a :href="url" target="_blank">{{ $t('tos') }}</a>
  </i18n>
  <!-- ... -->
</div>
js
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'

const messages = {
  en: {
    tos: 'Term of Service',
    term: 'I accept xxx {0}.'
  },
  ja: {
    tos: '利用規約',
    term: '私は xxx の{0}に同意します。'
  }
}

const i18n = createI18n({
  locale: 'en',
  messages
})

const app = createApp({
  data: {
    url: '/term'
  }
}).use(i18n).mount('#app')

TranslationProps

翻译组件的属性

签名:

typescript
export interface TranslationProps extends BaseFormatProps

keypath

签名:

typescript
keypath: string;

详情

可以指定的本地消息键

plural

签名:

typescript
plural?: number | string;

详情

选择消息的复数数量属性