当我想把对象发送到Route时,axios会返回ERR_NETWORK。我不知道CORS是否被卷入。
Here I show you the error
My services.js:
import axios from "axios";
export const apiClient = axios.create({
baseURL: 'https://laboratorio3-f36a.restdb.io/rest',
headers: {'x-apikey': '60eb09146661365596af552f',
'Access-Control-Allow-Headers' : '*',
'Access-Control-Allow-Origin' : 'http://localhost:8080',
'Access-Control-Allow-Credentials': '*',
'Accept': 'application/json',
},
});
export default{
transaction(purchaseData){
return apiClient.post(`/transaction/`, purchaseData)
},
getHistorial(id){
return apiClient.get(`/transactions/${id}`)
},
delete(id){
return apiClient.delete(`/transactions/${id}`)
},
edit(id){
return apiClient.put(`/transactions/${id}`)
}
}
这里我发送Object:
const Purchase = async () => {
console.log('Los datos son: ',purchaseData)
try {
console.log('Enviando....')
await lab3api.transaction(purchaseData);
console.log('Enviaooouu')
} catch(e) {
console.log("Error en la compra", e)
}
}
我试过安装cors库。我添加了标题Accessi-Control-Allow-Methods,但这也不起作用。我已经安装了一个扩展,据说允许CORS,等等,等等
1条答案
按热度按时间alen0pnh1#
是的,您必须获取ERR_network
1.配置在axios阅读此文档获得您的答案
document for axios config
验证API端点:请确保您使用的baseURL正确且API可访问。您可以尝试直接在浏览器中访问API端点,或使用cURL或Postman等工具来确认服务器是否按预期响应。