问题描述
这是我的等级
> Access to fetch at 'https://api.xxx' from origin 'https://xxx.cloudfront.net' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs,set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
polyfills-es2015.3eb4283ca820c86b1337.js:1 GET https://api.xxx net::ERR_Failed
e.fetch @ polyfills-es2015.3eb4283ca820c86b1337.js:1
> (anonymous) @ VM20:1
> x:1 Uncaught (in promise) TypeError: Failed to fetch
- AddEmployee component
- UpdateComponent
- Home
* EmployeeItem component
包含许多保存员工数据的列,在这些列中,我有update列,该列是重定向到更新组件的图标,我如何将员工的数据传递给{{ 1}}为了显示它们并允许对其进行修改,我无法使用react路由器历史记录对象,因为在EmployeeItem组件中未定义该对象,因为它不是路由,而react-router会忽略它。
是否有一种方法可以在不使用readux或其他状态管理器的情况下进行操作,我当时正在考虑the employee item component is just a line in a list
,但我不清楚如何执行此操作。
我正在使用react-router处理重定向
解决方法
要将数据从父级传递到子级,只需将其传递到组件本身的呈现中即可。这些叫做道具。
<EmployeeItem name = {Lyes} city = {Lisbon}/>
然后在组件内部
const EmployeeItem = props => {
return (
<h1>Employee {props.name} is from {props.city}</h1>
);
}