Aurelia:获取客户端响应没有我的数据

Aurelia: fetch-client response doesn't have my data

我已经为 fetch-client 苦苦思索了太久,我需要一些帮助。

我正在从 Skyscanner 获取一些数据。该请求命中了他们的 API 并且 Chrome 的开发工具在网络选项卡中将其列为带有代码 200 和正确响应正文的完整提取请求。

import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
@inject(HttpClient)
export class Flights {
    constructor(http){
        http.configure(config => {
          config
            .withBaseUrl('http://partners.api.skyscanner.net/apiservices/')
            .withDefaults({
                mode: 'no-cors',
                headers: {
                    'Accept': 'application/json',
                    'Content-type' : 'application/json'
                }
            });
        });

        this.data = "";
        this.http = http;
    }
  activate() {
    this.http.fetch('browsequotes/v1.0/GB/GBP/en-GB/UK/anywhere/anytime/anytime?apiKey=MYAPIKEYGOESHERE')
            .then(response => {
                console.log(response);
                console.log(response.response);
                console.log(response.content);
                console.log(response.data);
            })
            .catch(ex => {
                console.log(ex);
            }); 
  }
}

但是当打印响应对象时,它里面什么都没有:

Response {}
  body: null
  bodyUsed: false
  headers: Headers
  __proto__: Headers
  ok: false
  status: 0
  statusText: ""
  type: "opaque"
  url: ""
  __proto__: Response

所有剩余的 console.log 产品 undefined

我是不是用错了fetch-client?我错过了什么?

请注意,您收到了 opaque response (type: "opaque"). Opaque responses does not allow you to read them. This is due to the no-cors mode you set before. You should use the cors mode and SkyScanner should provide the proper headers for your API key which is something I think they don't do

我解决了我的问题,该问题可能属于同一标题,因此在此处留下答案,因为我在网上找不到任何东西。可能是我太笨了,但我以前也这样做过...

.then(response => {response.json()})
.then(data => console.log(data))

我为此苦苦思索了一天,结果发现解决方法是:

.then(response => response.json())
.then(data => console.log(data))

或者

.then(response => { return response.json()})
.then(data => console.log(data))

真的很简单,与 Aurelia 或 Fetch 无关,但了解 Javascript 语法。