axios http.post
时间: 2024-01-13 21:20:25 浏览: 99
以下是使用axios进行POST请求的三种方式:
1. 使用axios.post方法发送简单的POST请求:
```javascript
axios.post('/api/postData', { data: 'example' })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
```
2. 使用axios.post方法发送带有请求头的POST请求:
```javascript
axios.post('/api/postData', { data: 'example' }, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
```
3. 使用axios.post方法发送带有查询参数的POST请求:
```javascript
axios.post('/api/postData?param1=value1¶m2=value2', { data: 'example' })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
```
这些示例展示了使用axios库进行POST请求的不同方式,你可以根据自己的需求选择适合的方式来发送POST请求。
阅读全文
相关推荐


















