I have data in my database that may contains curly braces{{ }}
.
{{-- inside app.blade.php --}}
<!-- vue app -->
<div id="app">
...code
<div> {{ $data }} </div>
...code
</div>
so if I want to display it to the user this data cause problem if it's inside Vue app. and vue think it's javascript codes to execute.
for example if the $data
is equal to {{ title->links() }}
then I get an error and the whole app doesn't compile at all. (it passes the blade template).
[Vue warn]: Error compiling template:
invalid expression: expected expression, got '>' in
_s(title->links())
Raw expression: {{ title->links() }}
305| <div>{{ title->links() }}</div>
| ^^^^^^^^^^^^^^^^^^^^^^^
what is the best way to escape {{ }}
curly braces for user data (in Vue.js)??
You need use the v-pre
or v-html
directive:
<div v-pre>{{ data }}</div>
or
<div v-html="'{{ data }}'"></div>
ref link https://v2.vuejs.org/v2/api/#v-pre
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With