In VueJS, is there a way to interpolate a string within a string, either in the template or in the script? For example, I want the following to display 1 + 1 = 2 instead of 1 + 1 = {{ 1 + 1 }}.
<template>
{{ myVar }}
</template>
<script>
export default {
data() {
"myVar": "1 + 1 = {{ 1 + 1 }}"
}
}
</script>
Edit: to better illustrate why I would need this, here's what my actual data looks like:
section: 0,
sections: [
{
inputs: {
user: {
first_name: {
label: "First Name",
type: "text",
val: ""
},
...
},
...
},
questions: [
...
"Nice to meet you, {{ this.section.inputs.user.first_name.val }}. Are you ...",
...
]
},
...
],
this.section.inputs.user.first_name.val will be defined by the user. While I could rebuild the question properties as computed properties, I would rather keep the existing data structure in tact.
"myVar": "1 + 1 = "+(1+1)? But why? You might be approaching it the wrong way, tell us the actual thing you are trying to achieve, there might be a better way.<p>Hello, {{ user.first_name }}</p>and am looking for a solution that would allow this instead:<p>{{ sentence }}</p>, where sentence =Hello, {{ this.user.first_name }}.