假设我有这样一个消息对象:
{greetings: '{blah} is welcome'}
如何将超文本标记语言注入{blah}
参数?
我试过了,但不起作用:
{{ $t('greetings', {blah: '<foo>' + some_string + '</foo>'}) }}
发布于 2018-04-18 04:50:30
对于Vue 2.0,things have changed
如果您的消息对象是:
{greetings: '<foo>{blah}</foo> is welcome'}
那么在模板端,你应该具备以下条件:
<p v-html="$t('greetings', {blah: some_string})"></p>
同样适用于<div v-html="..."></div>
,当然也适用于其他标签。请参阅https://github.com/kazupon/vue-i18n/issues/73
发布于 2016-06-17 12:20:32
您必须向我展示您试图对该消息做什么,就像在HTML中显示它一样,但是第一次传递时,它似乎是您想要的
this.msg = '<foo>' + some_string + '</foo>';
然后,在您想要显示此消息的HTML中,您可以说:
{{{ msg }}}
注意三括号,这意味着它将msg
解释为原始的超文本标记语言,而不是转义字符串...使用时要小心。如果msg
纯粹是由前端设置的东西,那么也没问题;只是不要让some_string
是用户输入的数据。
发布于 2020-10-01 17:02:29
您可以使用:
$t('greetings', {blah: some_string})
在他们的en.json中
{
greetings: '<foo>{blah}</foo> is welcome'
}
https://stackoverflow.com/questions/37872212
复制相似问题