Server routes and API
📖 Scenario: You are building a simple Vue app that fetches a list of books from a server API and shows them on the page.The server has a route /api/books that returns a list of book objects with id and title.
🎯 Goal: Create a Vue component that fetches the books from the /api/books route and displays their titles in a list.
📋 What You'll Learn
Create a reactive variable to hold the books list
Create a variable for the API endpoint URL
Use the
fetch API inside onMounted to get the booksRender the list of book titles in the template using
v-for💡 Why This Matters
🌍 Real World
Fetching data from server APIs and showing it in a web app is a common task in building interactive websites and apps.
💼 Career
Understanding how to connect Vue components to backend APIs is essential for frontend developers working on real-world projects.
Progress0 / 4 steps