【发布时间】:2021-02-21 21:34:25
【问题描述】:
我使用Vuei18n 包。我的应用程序中有很多字符串在数据对象中定义或作为道具传递到自定义组件中,需要翻译。
data() {
return {
title: this.$t('main.title'),
stuff: [
{
name: this.$t('main.name_1')
},
{
name: this.$t('main.name_2')
}
]
}
}
或
MyCustomComponent(:name="$t('main.custom_component_name')")
问题是,如果我更改语言环境,这些字符串将不会被翻译。直接在模板部分定义的那些字符串在更改语言环境后立即按预期进行翻译。
【问题讨论】:
-
看起来您需要更改数据结构以将这些对象作为
string的i18n值发送或创建某种映射 -
嗨,我的回答有帮助吗?
标签: vue.js internationalization vue-i18n