Installing and Using Axios inVuejs
In this tutorial we will learn about installing and using Axios in VueJs. Before we start our discussion with installing axios, let us first discuss what axios really is? Axios is Promise based HTTP client for the browser and node.js. axios is basically used to makeXMLHttpRequests from the browser. Similarly its other features include make http requests from node.js, Support the Promise API, Intercept request and responses, Transform request and response data, Cancel requests, Automatic transforms for JSON data, besides it also has Client side support for protection against XSRF.
Now, lets move onto installation of Axios, axios can be installed using cdn, bower or with npm. However in this tutorial we will install axios using npm. for installation of axios we will need to install webpack and vuejs which is discussed in the previous session of this tutorial. Now moving into the installing we will need to add the following code into root directory of the command prompt.
and that's it we just installed axios, now go to index.js file that was created in the previous part and add the following line into it.
after this we can use axios in our regular view pages.
here is the example of get request with axios:
and here is the example of post request with axios:
So in this tutorial we learned about installation and simple usage of axios to send and receive requests from the client.