axios.get(url, { params })
即:
axios.get('your_endpoint', {
params: {
key1: 'value1',
key2: 'value2',
}
})
.then(response => {
// 处理响应数据
})
.catch(error => {
// 处理错误
});
axios.get也可以使用
即:
axios.get('your_endpoint?key1=value1&key2=value2')
.then(response => {
// 处理响应数据
})
.catch(error => {
// 处理错误
});
axios.post(url, JSON.stringify(data))
使用 axios.post(url, data)
时,Axios 默认将数据视为 JSON 格式.并设置请求头的 Content-Type 为 "application/json"。在这种情况下,你只需传递一个 JavaScript 对象作为 data
参数,Axios 会自动将其转换为 JSON 字符串。
即:
axios.post('your_endpoint', data)
.then(response => {
// 处理响应数据
})
.catch(error => {
// 处理错误
});