We'll be using
axios as the HTTP client to connect to our API. First, we need to install it:
npm install axios --save
Next, let's set some config defaults for
axios which will be applied to every request we make. Open
src/main.js and add the code below to it:
// src/main.js import axios from 'axios' // add these before Vue is instantiated window.axios = axios axios.defaults.baseURL = 'http://127.0.0.1:3333'
First, we import
axios, then reference it globally so we could use it in other places without having to import it individually in those places. Lastly, we set the baseURL config to our API URL (
http://127.0.0.1:3333) so we don't have to add it every time we make a request to our API.