如何将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>
答案 0 :(得分:7)
编辑2019:
@devman在评论中回答is outdated。请改为使用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
我希望这有帮助!