如何在 json 文件中使用 mustache 标签并从 Vue 中获取值?

How to use mustache tag in json file and get value from Vue?

我正在尝试 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}} 的值,它会相应地改变。 我该怎么做?

谢谢。

{{ $t('Msg1', { totalResults: 10 }) }

https://kazupon.github.io/vue-i18n/guide/formatting.html#named-formatting