[英]Axios: Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
I am getting the title error after running the following function in React: 在React中运行以下功能后,出现标题错误:
const postToApi = (event) => {
event.preventDefault();
axios.post(process.env.API_POST_URL, {step : "3"})
// API_POST_URL: http://localhost:4000/api/donate
.then(res => {
console.log(res);
console.log(res.data);
})
};
My React app is on localhost:3000. 我的React应用程序位于localhost:3000上。 Mentioning this because the file causing the error is: isURLSameOrigin.js:51
提及此问题是因为引起错误的文件是:isURLSameOrigin.js:51
Sorry, my reputation is not high enough to leave a comment and ask questions. 抱歉,我的声誉不够高,无法发表评论并提出问题。 Have you recently added the URL to your .env?
您最近是否将该URL添加到了.env? If so try stopping your npm/yarn and start it again.
如果是这样,请尝试停止您的npm / yarn,然后重新启动。 Applications compile your .env at the beginning of your dev server.
应用程序在开发服务器的开头编译.env。 If that does not work have you tried placing the URL directly into it?
如果这样不起作用,您是否尝试过将URL直接放入其中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.