axios 和 ajax 的使用方法基本一样,只有个别参数不同;
一、axios
axios({ url: 'http://jsonplaceholder.typicode.com/users', method: 'get', responseType: 'json', // 默认的 data: { //'a': 1, //'b': 2, } }).then(function (response) { console.log(response); console.log(response.data); }).catch(function (error) { console.log(error); })
二、ajax
$.ajax({ url: 'http://jsonplaceholder.typicode.com/users', type: 'get', dataType: 'json', data: { //'a': 1, //'b': 2, }, success: function (response) { console.log(response); } })
使用的基本形式是这样,其他地方大同小异;
另外Vue 官方建议用 axios 代替 vue-resourse,所以在这里不做vue-resourse的探讨;