Answer the question
In order to leave comments, you need to log in
Why is filter not working in Vue.js?
app.vue file:
<template>
<div id="app">
<Search v-model="search"></Search>
<ul>
<li v-for="(element, idx) in searchName" :key="idx">
{{ element.name }} - {{ element.age }}
</li>
</ul>
</div>
</template>
<script>
import Search from "./components/Search.vue";
export default {
name: "App",
components: {
Search
},
data() {
return {
search: "",
elements: [
{
name: "Bob",
age: 30,
},
{
name: "Mark",
age: 50,
}
]
}
},
computed: {
searchName() {
return this.elements.filter((elem) => {
return elem.name.toLowerCase().includes(this.search.toLowerCase());
})
}
}
}
</script>
<template>
<div id="person">
<label>
Search Name:
<input type="text" />
</label>
</div>
</template>
<script>
export default {
name: "Search"
}
</script>
Answer the question
In order to leave comments, you need to log in
v-model needs to be set at the input itself, and you are trying to bind v-model for the Search component with props.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question