[Vuejs]-How do I inject a variable into a string within the template?

0👍

You can use like the following:

<ul>
    <li
        class="validation-labels"
        v-for="(label, key) of labels" v-bind:key="key">
        {{ validationReqs(label.type, label.value) }}
    </li>
</ul>

In your computed property:

validationReqs(type, value) {
  return this.constants.validationRequirements[type]
         .replace('{{ value }}', value);
}

Leave a comment