如何解决如何在vue.js中转义大括号
我的 数据库 中有 数据 ,其中可能包含大括号{{ }}
。>
{{-- inside app.blade.php --}}
<!-- vue app -->
<div id="app">
...code
<div> {{ $data }} </div>
...code
</div>
因此,如果我想向用户显示此数据,则该数据将在Vue应用程序内部引起问题。并认为这是要执行的javascript代码。
例如,如果$data
等于{{ title->links() }}
,则出现错误,整个应用程序完全无法编译。 (它通过刀片模板)。
[Vue warn]: Error compiling template:
invalid expression: expected expression,got '>' in
_s(title->links())
Raw expression: {{ title->links() }}
305| <div>{{ title->links() }}</div>
| ^^^^^^^^^^^^^^^^^^^^^^^
在用户数据中使用{{ }}
大括号转义的最佳方法是什么?(在Vue.js中)?
解决方法
您需要使用v-html
或<div v-pre>{{ data }}</div>
指令:
<div v-html="'{{ data }}'"></div>
或
renderAllStates = () => {
return Object.entries(data).map(([key,value]) =>
<Collapsible key={key} trigger={key}>
<p>
This is the collapsible content. It can be any element or React
component you like.
</p>
<p>
It can even be another Collapsible component. Check out the next
section!
</p>
</Collapsible>
);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。