从本地主机从 React

编程入门 行业动态 更新时间:2024-10-22 07:28:07
本文介绍了从本地主机从 React-Redux 发出 HTTP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是 React Redux 的新手,而且我已经做过了:

I am new to React Redux, and All I already did:

1) 激活我的后端服务器 (localhost:5000)

1) activate my backend server (localhost:5000)

2) 使用 npm start (localhost:8080) 激活我的前端服务器

2) activate my front-end server using npm start (localhost:8080)

3) 我试图通过使用

this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile});

4) 使用 atlas-saga,并调用与调度相关的服务函数:

4) Using atlas-saga, and call my service function associated with the dispatch :

let result = yield call(Atlas.uploadFile, action.email, action.file);

5) 定义函数为:

export const uploadFile = (email, file) =>{return fetch(`${BASE_URL}/v1/files/${email}/policies`, {方法:'POST',标头:{} ,正文:{'文件':文件}}).then(response => response.json())}

在我尝试在我的反应中运行一个函数(一个调用调度的函数)后,它给了我他们找不到路由的错误.这是来自控制台的错误消息.

After I try to run a function at my react( a function that calls the dispatch), it gives me errors that they cannot found the route. This is the error message from the console.

Fetch API 无法加载 api-staging.autoarmour.co/v1/files/fakeemail@gmail/policies.请求的资源上不存在Access-Control-Allow-Origin"标头.因此,不允许访问 Origin 'localhost:8080'.响应的 HTTP 状态代码为 500.如果不透明响应满足您的需求,请将请求的模式设置为no-cors"以在禁用 CORS 的情况下获取资源.

是的,我没有创建任何减速器,只是将上传文件的纯函数.谢谢

Yes, I did not create any reducer, just pure function that will upload a file. Thank you

推荐答案

我解决了,哇哦!!!错误消息意味着它根本没有在后端连接.您需要确保它已连接.我通过将我的 redux 连接到我的 react 组件来解决它.谢谢各位

I SOLVE IT, WOHOO!!! The error message means that its not connected at the backend side at all. You need to make sure that it is connected. I solve it by connecting my redux to my react component. Thanks guys

干杯!

更多推荐

从本地主机从 React

本文发布于:2023-11-16 11:16:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机   React

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!