[Vuejs]-Vuejs, How can I resolve expressions within a string got as a prop?

0👍

You could move the login inside your component by making use of 2 props, for example name, which is a String, and maritalStatus, which is either a String or Boolean depending on your needs (the example assumes a Boolean for maritalStatus). Then inside your component construct the message you want to display:

<label>
  Position of {{element.name}} <span v-if="maritalStatus">Free</span><span v-else>Married</span>
</label>

You could also use string literals:

myAnnoyingProp: `Position of ${name} ${maritalStatus}`

Leave a comment