Menu
CoddyTech

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 icon

Challenge

Medium

Make 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals