Axios
Axios是一个基于Promise的HTTP库,可以用在浏览器和node.js中
安装方法
GET方法
1 2 3 4
| axios .get(URL) .then(response => (this.info = response)) .catch(err => console.log(err))
|
GET方法传递参数的格式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| axios.get('/user?ID=12345') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
|
POST方法
1 2 3 4 5 6
| axios .post('https://www.runoob.com/try/ajax/demo_axios_post.php') .then(response => (this.info = response)) .catch(function (error) { console.log(error); });
|
POST 方法传递参数格式如下:
1 2 3 4 5 6 7 8 9 10
| axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
|
Axios API
可以通过向axios传递相关配置来创建请求