如何将HTML绑定到Vue组件属性?
在我的PHP脚本中,我有:
$html = '<div>some text</div>';
$box = "<box_includes
html_text='$html'
></box_includes>";
在我的Vue模板中:
<template id="template_box_includes">
{{ html_text }}
</template>
但是,在我的浏览器中,我看到了所有文本,包括标签,它被识别为文本:
<div>some text</div>
编辑2019:
如@devman在评论中所述,以下答案已过时。请v-html
改用:
<template v-html="html_text"></template>
较旧的答案
在Vue JS中,使用双花括号可以转义HTML。您需要使用三个来避免像这样转义html:
<template id="template_box_includes">
{{{ html_text }}}
</template>
您可以在文档的此页面上了解更多信息:http : //vuejs.org/guide/syntax.html#Raw-HTML
我希望这有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句