访问 XMLHttpRequest at ... from origin 'http://localhost:3000' 已被 CORS 策略阻止

时间:2021-05-14 12:56:59

标签: reactjs

private processFormSubmission = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
        e.preventDefault();
        this.setState({ loading: true });
        axios.patch(`https://609e417f33eed800179581a7.mockapi.io/api/customers/data/${this.state.id}`, this.state.values).then(data => {
            this.setState({ submitSuccess: true, loading: false })
            setTimeout(() => {
                this.props.history.push('/');
            }, 1500)
        })
    }

enter image description here

我创建了 CRUD 应用程序,当我使用编辑功能时,我收到了这样的错误。请帮助我。

1 个答案:

答案 0 :(得分:0)

我们可以做两件事:

  1. 我们可以要求中间层/API 团队在他们的 Allow -CORS 列表中允许您的 UI 的 FQDN。
  2. 在我的本地文件中,我在 "proxy": "http://127.0.0.1:5000" 中添加了 package.json

enter image description here

enter image description here