I'm struggling to extract data from a child array and utilize it in my v-if condition.
Below are my data and code. Any assistance would be appreciated, even if it's just pointers to the right documentation.
<div class='post' v-for="message in messages" v-if='["Food","Featured"].includes(tag) || tag === ""'>
<h2>{{message.text}}</h2>
<div v-for="category in message.categories">
{{category.name}}
</div>
</div>
Rather than
v-if='["Food","Featured"]
, I've been attempting v-if='[category in message.categories]
Clearly, that's not correct. How can I correctly pass data from a nested array UP to the v-if
statement?
The data is provided below:
[
{
"text":"Featured food content",
"categories":[
{
"name":"Featured",
"ID": "189"
},
{
"name":"Food",
"ID": "190"
}
]
},
{
"text":"Featured content",
"categories":[
{
"name":"Featured",
"ID": "189"
}
]
}
]
Thank you for all your help. This is what I came up with until I figure out how to use computed properties properly.
<template v-for="message in messages">
<div class='post' v-if='message.categories.map(c => c.name).includes(tag) || tag === ""'>
<h2>{{message.text}}</h2>
<div v-for="category in message.categories">
{{category.name}}
</div>
</div>
</template>