javascript - 如何使用 vue-i18n 翻译渲染项目列表?
问题描述
我是vue.js
&的新手,vue-i18n
想知道如何用v-for
.
这是针对使用vue.js
. 我尝试在data
函数内引用语言环境,但这会破坏视图。
JS
new Vue({
i18n,
el: '#my-form',
data: {
myList: [
{key: 1, title: 'Option 01'},
{key: 2, title: 'Option 02'},
{key: 3, title: 'Option 03'}
]
}
})
<div>
<label>{{ $t('label.options') }}</label>
<div>
<button v-for="option in myList">{{ title }}</button>
</div>
</div>
我需要翻译列出的每个选项并为其他selects
和复制lists
。非常感谢任何帮助,因为我不确定如何继续。
解决方案
myList
改为使用计算属性,您可以使用 i18n 中定义的选项title: this.$t(options.1)
。
推荐阅读
- android - 单选recyclerview item kotlin
- c++ - 在 Visual Studio 2019 中跟踪内存泄漏
- c# - 如何从 .Net Framework 中可用的 HttpContext.Current.Response.Output 转换为 .Net Core 的对象?
- javascript - 模板文字在 Chrome 上引发未捕获的语法错误
- google-chrome - 下载文件时获取文件 URL
- postgresql - 如何在 PostgreSQL 中通过 varchar 选择带有 case-when 开关的整理顺序进行排序
- c# - 无法选中 ASP.NET Core MVC 视图中的复选框
- reactjs - 将 React 组件实现为 html 字符串
- c# - 为什么我无法使用驱动程序连接字符串连接到 MySql .Net,因为它与 Delphi 的 TADOQuery 一起使用?
- python - python3:timedrotatingfilehandler 日志轮换问题与具有多个脚本的相同日志文件