Recently, I've been working on implementing a filter for a search bar.
However, I've noticed that whenever I input something into the search bar, there is a noticeable delay as it loads the entries. I'm not sure if this issue is related to rendering problems or if my approach is simply not suitable given the size of the object, which contains around 2500 entries.
The object structure includes keys such as:
{
key1: {
title: 'title',
description: 'description',
footerContent: 'footerContent'
},
key2: {
title: 'title',
description: 'description',
footerContent: 'footerContent'
},
key3: {
title: 'title',
description: 'description',
footerContent: 'footerContent'
}
}
To filter this object, I have created the following computed function:
filteredItems() {
if(this.searchQuery) {
return Object.fromEntries(
Object.entries(this.items).filter(([key]) => {
return this.searchQuery
.toLocaleLowerCase()
.split(" ")
.every(
(word) =>
key.toLocaleLowerCase().includes(word)
)
})
)
}
return this.items
}
Subsequently, in the template, I use a v-for loop like so:
<tbody>
<tr v-for="item, key in filteredItems" :key="key">
<td class="align-middle">{{key}}</td>
<td><input type="text" class="form-control" v-model="item.title"/></td>
<td><input type="text" class="form-control" v-model="item.description"/></td>
<td><input type="text" class="form-control" v-model="item.footerContent"/></td>
</tr>
</tbody>