In the handling of HTTP requests, the use of Vue-resource has been deprecated, but the use of the latest Axios, the following is a simple introduction.
Installation
Using node
Using CDN
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
Basic use method GET request
//Make a request for a user with a given IDAxios.Get('/user?id=12345'). Then (function (response) {Console.log (response); }) .Catch(function (Error) {Console.log (error); });//optionally the request above could also is done asAxios.Get('/user', { params: {ID:12345}}). Then (function (response) {Console.log (response); }) .Catch(function (Error) {Console.log (error); });
POST request
Axios.post ('/user', { 'Fred', ' Flintstone ' }) . Then (function (response) { Console.log (response); }) . Catch (function (Error) { console.log (error); });
Execute multiple requests at the same time
function Getuseraccount () { return Axios. Get('/user/12345');} function Getuserpermissions () { return Axios. Get('/user/12345/permissions');} Axios.all ([Getuseraccount (), Getuserpermissions ()]) . Then (Axios.spread (function (acct, perms) { // Both Requests( )));
The use of this method is actually the same as the original Ajax, one can understand.
Reference article: https://juejin.im/entry/587599388d6d810058a7a41a
Axios Processing HTTP Requests