I have a string of html where I get from Editor and stored in the database.
<h3><a href="#" rel="noopener noreferrer nofollow"><em><strong>Profile Of User:</strong></em></a></h3><p></p><p>{{user}}</p>
I want to retrieve it from the database and render it as HTML. when I use v-html, it will be rendered as:
<v-card-text v-html="content"></v-card-text>
Profile Of User:
{{user}}
How to render {{hello}} from data property if I have data property like this:
data() {
return {
user: "Lim Socheat",
content:"<h3><a href="#" rel="noopener noreferrer nofollow"><em><strong>Profile Of User:</strong></em></a></h3><p></p><p>{{user}}</p>"
};
},
Expected Result:
Profile Of User:
Lim Socheat
because {{ user }} will be rendered as Lim Socheat
I found the answer. hope it helps someone in the future.
Orginal post: https://forum.vuejs.org/t/evaluate-string-as-vuejs-on-vuejs2-x/20392/2
VueJS - Interpolate a string within a string
Make content a computed property. And then use it like this:
You can use all variables defined in data in this way.
Update: Since OP is getting the HTML string from backend, they need to replace the variables in this case. We have kept a map of all variables that might come and then we are creating a Regex dynamically to replace the said key from code.