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...