Is there a more efficient way to iterate through a filtered list with a given input parameter in vue.js?
I want to avoid using filtering within the template like
<li v-for="x in todos_filtered" v-if="x.person == 'Mike'">
when dealing with a large number of records.
Below is the code that is returning an empty list instead of the expected 2 elements.
<html>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="583d28283e293f283c26753b"><strong>[...]</strong></a>/dist/vue.js"></script>
<body>
<div id="app">
<ul>
<li v-for="x in todos_filtered('Mike')">
{{ x.text }}
</li>
</ul>
</div>
<script>
myObject = new Vue({
el: '#app',
data: {
todos: [
{ person: 'Mike', text: 'Learn JavaScript' },
{ person: 'Luke', text: 'Learn Vue.js' },
{ person: 'Mike', text: 'Build Something Awesome' }
]
},
computed: {
todos_filtered(person) {
return this.todos.filter((x) => x.person === person);
}
},
})
</script>
</body>
</html>