如何将HTML绑定到Vue组件属性?
在我的PHP脚本中,我有:
$html = '<div>some text</div>';
$box = "<box_includes
html_text='$html'
></box_includes>";
Run Code Online (Sandbox Code Playgroud)
在我的vue模板中:
<template id="template_box_includes">
{{ html_text }}
</template>
Run Code Online (Sandbox Code Playgroud)
但在我的浏览器中,我看到所有文本,包括标签,它被识别为文本:
<div>some text</div>
Run Code Online (Sandbox Code Playgroud)
在Vue JS中,双括号的使用是逃避HTML.您需要使用三个以避免转义html,如下所示:
<template v-html="html_text"></template>
Run Code Online (Sandbox Code Playgroud)
您可以在此文档的页面上了解更多信息:http://vuejs.org/guide/syntax.html#Raw-HTML
我希望这有帮助!
归档时间: |
|
查看次数: |
7225 次 |
最近记录: |