Reactjs 异步等待和获取总是返回错误

Reactjs 异步等待和获取总是返回错误,reactjs,async-await,Reactjs,Async Await,我正在使用fetch获取数据,我总是会遇到以下错误: async fetchPhotos(token, placeid) { const _PLACEID = placeid ? placeid : this.props.attributes.placeid; const _TOKEN = token ? token : this.props.attributes.token; if (!_TOKEN || !_PLACEID) { return fal

我正在使用fetch获取数据,我总是会遇到以下错误:

  async fetchPhotos(token, placeid) {
    const _PLACEID = placeid ? placeid : this.props.attributes.placeid;
    const _TOKEN = token ? token : this.props.attributes.token;

    if (!_TOKEN || !_PLACEID) {
      return false;
    }

    const url = `https://maps.googleapis.com/maps/api/place/details/json?key=${_TOKEN}&placeid=${_PLACEID}`;
    console.log(url);

    try {
      const response = await fetch(url);
      console.log(response);
    } catch (error) {
      console.log('you got an error bro: ' + error.toString());

      this.setState({
        apiResponseCode: '400',
        apiErrorMessage: error.toString(),
        loading: false,
      });
    }
  }

但是,如果我手动将url插入浏览器,它工作正常,因此我不知道它为什么一直出错?

因此,结果表明错误与CORS有关。我需要通过代理服务器运行获取请求

因此,我没有直接打电话给谷歌,而是打电话给如下服务器:

const url = 'http://myproxyserver.test/wp-json/google-places/v1/get-reviews';

错误消息是什么?是否在构造函数中绑定函数以访问此.props?