I'm currently facing a challenge in finding a solution to what appears to be a simple problem.
Within a template, I am using a v-for loop to generate some content. In this content, I need to execute a function to check if the contentID matches an ID from a separate list. If there is a match, I need to display that data within my loop. However, the current method involves running the function multiple times, as shown below:
methods: {
findClientName (clientId) {
for (let name of this.clientList) {
if (name.id == clientId) {
return {
name
}
}
}
}
<v-card-text>
{{ findClientName(item.client_id).name.f_name }}
{{ findClientName(item.client_id).name.l_name }}
</v-card-text>
It feels inefficient to call the method repeatedly on each data point. Is there a way to store the result in a local variable within the template, like this:
{ clientData = findClientName(item.client_id) }
{{ clientData.f_name }}
{{ clientData.l_name }}
What am I overlooking or not considering?