I have a js file containing array and objects. I need to style some properties from these arrays. For example
myArray= [
{
id: 1,
name: 'honda',
description: 'to buy the latest car, click here'
},
{
id: 2,
name: 'tesla',
description: 'to buy the latest car, click here'
}
]
Let's say I want to style the description property so that I can bind a link there.
I figure that the way to do it is to use raw html. But in my case, I'm going to include it to my array. Is this possible? I have tried to search this question everywhere but there's no explanation for this case. Thank you so much.
description: '... <a href="#">...</a>...', then use<span v-html="item.description"></span>, make sure its not user supplied though, else XSS is possible. The only issue comes if you want to do vue in the string, ie a@click="$router.push('/')"etc, then your want to use the runtime complierv-htmlas you already indicated, eg<p v-for="obj in myArray" :key="obj.id" v-html="obj.description"></p>descriptionproperty are styled? I mean, for example, in another new object (another car), I don't want to add any v-html in thedescriptionproperty.v-htmldoesn't require there to be HTML tags present. It will just output yourdescriptionvalue as-is