简体   繁体   English

引发了跨域错误。 react 无权访问 react 开发中的实际错误 object

[英]A cross-origin error was thrown. react doesn't have access to the actual error object in development in react

i am trying to clone data from props to state inside constructor.我正在尝试将数据从道具克隆到构造函数内的 state。

this.state = {
  showAttemptModal: false,
  showProgressbar: true,
  data: JSON.parse(JSON.stringify(this.props.data))
}

But getting cross-origin error.但是出现跨域错误。 Why this is happening.为什么会这样。

If you have setup your server to support CORS and still getting this error, most likely it is an issue with reactjs while processing response from the server.如果您已将服务器设置为支持 CORS 并且仍然出现此错误,则很可能是 reactjs 在处理来自服务器的响应时出现问题。 In my case it was happening while trying to parse invalid response into JSON.就我而言,它是在尝试将无效响应解析为 JSON 时发生的。

CORS error has nothing to do with cloning data from props to state. CORS 错误与将数据从 props 克隆到 state 无关。 You need to pass following property for same in your request header while fetching data from API:在从 API 获取数据时,您需要在请求 header 中传递以下属性:

{Access-Control-Allow-Origin:"*", "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:引发了跨域错误。 React 无法访问开发中的实际错误 object - Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development × 未处理的拒绝(错误):抛出了跨域错误。 React 无权访问开发中的实际错误对象 - × Unhandled Rejection (Error): A cross-origin error was thrown. React doesn't have access to the actual error object in development "<i>Uncaught Error: A cross-origin error was thrown.<\/i>未捕获的错误:引发了跨域错误。<\/b> <i>React doesn&#39;t have access to the actual error object in development<\/i> React 无法访问开发中的实际错误对象<\/b>" - Uncaught Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development 未捕获的错误:在 React 中抛出跨源错误 - Uncaught Error: A cross-origin error was thrown in React React js tsx codesandbox问题 抛出了跨域错误,lodash.isequal - React js tsx codesandbox problem A cross-origin error was thrown and lodash.isequal 更新 React state 变量会引发跨域错误 - Updating a React state variable throws cross-origin error json.parse 触发 React / MERN 中的跨域错误 - json.parse triggers cross-origin error in React / MERN 为什么 postman 不会出现跨域块错误? - why postman doesn't get cross-origin block error? Codesandbox.io 引发了跨域错误问题 - A cross-origin error was thrown problem with Codesandbox.io SecurityError: “cross-origin object” with window.open 在 React 上的弹出窗口 - SecurityError: “cross-origin object” with window.open popup on React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM