我有错误
从源 ' http://localhost:3000 '获取在 ' http://localhost:5000/admin/authenticate '的访问已被 CORS 策略阻止:没有 'Access-Control-Allow-Origin' 标头存在于请求的资源。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
我的 ApiManager
function login(username, password) {
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*' },
body: JSON.stringify({ username, password })};
return fetch(`http://localhost:5000/admin/authenticate`, requestOptions)
.then(handleResponse)
.then(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('user', JSON.stringify(user));
return user;
}
);
}
Run Code Online (Sandbox Code Playgroud)
在后端 Asp.Net Core 2.2 (Startup.cs) 中,我写道:
services.AddCors(options => …Run Code Online (Sandbox Code Playgroud) 我需要将我的 React 应用组件切换到 Typescript。
我安装了 TS 包并创建了一个tsconfig.json文件,react-app-env.d.ts文件。我还将扩展名从 .js 更改为 .tsx。但是在其中一个组件中我有一个错误。例如:在<div>
<div class="main-div">
<div class="panel">
<h2>????</h2>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
输入'{孩子:元素[]; 类:字符串;}' 不能分配给类型 'DetailedHTMLProps, HTMLDivElement>'。类型“DetailedHTMLProps, HTMLDivElement>”.ts(2322) 上不存在属性“class”