要使用 Axios 发起类似于 curl 请求的请求,你可以使用以下步骤:
npm install axios
或者
yarn add axios
import axios from 'axios';
axios.get('https://api.example.com/data')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
axios.post('https://api.example.com/data', {
key1: 'value1',
key2: 'value2'
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
headers 属性:axios.get('https://api.example.com/data', {
headers: {
'Authorization': 'Bearer your_token_here'
}
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
这些示例代码展示了如何使用 Axios 发起类似于 curl 请求的请求。你可以根据需要进行修改和扩展。