Installation of Axios
Much like Vuex, you have multiple ways of including Axios
in your project. The simplest is pasting in a <script>
tag pointing to the Content Delivery Network (CDN) for the library:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
The other option is to use the Node Package Manager, npm
. Within an existing Vue application, you can install Axios
as follows:
npm install axios
Once you have done this, your Vue components can then import the library as follows:
import axios from 'axios';
How you use Axios
will depend on the API you are interacting with. Here is a simple example of hitting an imaginary API:
axios.get('https://www.raymondcamden.com/api/cats') .then(res => { this.cats = res.data.results; }) .catch(error => { console.error(error); });
In the preceding example, we are performing a GET
request (GET
is the default) against an imaginary...