I'm currently working on my vue
-app and I’m looking to implement a search feature for various topics. Here’s a sample of the data structure:
people: [
{
name: 'Mr.X',
gender: 'Male',
location: {
address: 'some streetname',
zipcode: '12345',
city: 'Berlin',
lng: 'longitude',
lat: 'latitude',
},
skills: [
{ label: 'foo' },
{ label: 'bar' },
],
},
...etc
]
To achieve this, I created a computed property in my component like so:
computed: {
filteredResults() {
return this.people.filter((person) => {
let values = Object.values(person).join().toLowerCase();
return values.includes(this.search.toLowerCase());
})
}
}
The HTML section related to the search component looks as follows:
<input type="text" v-model="search" />
<div v-for="(person, index) in filteredResults" :key="index">
<p>{{ person.name }}</p>
</div>
As it stands, the search only checks against the name field. How can I include all properties for searching? In other words, when I search for “Berlin”, it should display all data associated with that keyword.