Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Vue.js 2 Web Development Projects

You're reading from   Vue.js 2 Web Development Projects Learn Vue.js by building 6 web apps

Arrow left icon
Product type Paperback
Published in Nov 2017
Publisher Packt
ISBN-13 9781787127463
Length 398 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
CHAU GUILLAUME CHAU GUILLAUME
Author Profile Icon CHAU GUILLAUME
CHAU GUILLAUME
Arrow right icon
View More author details
Toc

FAQ - Consuming an API


In this section, we will create the FAQ page, which will get data from the server. It will display a loading animation and then the list of questions and answers.

Server setup

This is our first app that will communicate with a server. You will get a server with a ready-to-use API.

You can download the server files (https://github.com/Akryum/packt-vue-project-guide/tree/master/chapter5-download). Extract them into another folder than our app and run the following commands to install the dependencies and launch the server:

cd server_folder
npm install
npm start

You should now have the server running on port 3000. When this is done, we can continue building our app with a real backend this time!

Using fetch

In the FAQ.vue Single File Component, we will use the standard fetch API of the web browser to retrieve the questions from our server. The request will be a very simple GET request to http://localhost:3000/questions with no authentication. Each question object will have title...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image