【问题标题】:How to use mustache tag in json file and get value from Vue?如何在 json 文件中使用 mustache 标签并从 Vue 中获取值?
【发布时间】:2020-06-16 11:24:12
【问题描述】:

我正在尝试 vue-i18n 并已根据语言将翻译保存在文件中。

en.json

{
    "Msg1": "You have ",
    "Msg2": " results."
}

showResult.vue

{{ $t('Msg1')}} {{totalResults}} {{ $t('Msg2')}}

这可以显示示例输出,但是如果我想在 en.json 的单行中将所有内容组合在一起,例如:

{
    "Msg1": "You have {{totalResults}} results."
}

而对于 showResult.vue 我已更改为,我不确定它是否正确:

{{Msg1}}

下面是我希望得到的示例输出:

You have 10 results.

10 是来自 {{totalResults}} 的值,它会相应地改变。 我该怎么做?

谢谢。

【问题讨论】:

  • 你可以试试这样的模板文字Msg1: You have ${totalResults} results.
  • 我不能放反引号。但是用带有反引号的totalResults 覆盖语句 (`)
  • 您好,感谢您的回复。我都试过了,但都失败了,输出会是这样的:You have ${pageStart} results.

标签: json vue.js internationalization mustache vue-i18n


【解决方案1】:

【讨论】:

  • 您好,感谢您的回复。 {{totalResults}} 应该会相应更改,因此我无法为其设置值。
  • 单人{}You have {totalResults} results."@Qness
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-24
  • 2022-08-17
  • 2013-10-29
  • 2021-10-20
相关资源
最近更新 更多