Computed Search Results
Part of the Fundamentals section of Coddy's Vue journey. Lesson 28 of 55.
A search view should derive matches without destroying its source data. This computed list matches titles using a trimmed, lowercase query.
const query = ref('');
const matches = computed(() => books.value.filter(book =>
book.title.toLowerCase().includes(query.value.trim().toLowerCase())
));The source array remains available when the query changes or becomes empty. Normalize both sides for a case-insensitive comparison. Several conditions can be combined inside the predicate, such as matching text and an unfinished status.
Challenge
MediumMake input#search filter the supplied supplies by a case-insensitive name substring, ignoring edge spaces. Render the computed matching list in ul#result. Clearing search restores every item; searching must not delete source records.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks6Working with Lists
Adding List ItemsRemoving by IdComputed Search ResultsCounts from ListsRecap: List Manager