未检测到访问控制来源 reactjs

No Access Control Origin is not detected reactjs

我正在尝试提取 API 数据,当我这样做时,我收到了 "No Access Control Origin detected" 的错误消息,即使我添加了访问控制允许来源 header

当我在 Chrome/Firefox 中启动 npm 时它不起作用,但是当我使用 IE 时它起作用

这是我的代码:

 componentDidMount() {
        fetch(url , {
            mode: 'cors',
            headers: { 
            'X-API-KEY': API_KEY,
            'Access-Control-Allow-Origin': 'https://localhost:3000/',
            'Access-Control-Allow-Credentials': 'true',
            'Access-Control-Allow-Headers': 'Content-Type, Origin, Accept, Authorization',
            'Accept': 'application/json',
            'Content-Type': 'application/json'
            }

        })
            .then(res => res.json())
            .then(json => {
                this.setState({
                    isLoaded: true,
                    items: json,
                })
            })
        };

我认为这是您使用的 API 的服务器端问题。请确保选项请求具有正确的 Access-Control headers 并且可以接受您的请求。