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的探討;