我正在尝试使用fetch客户端接收包含大数组的json对象。 我可以在包含值的控制台中看到Promise,但是当尝试从响应中查看数据时,它是一个空对象{}。 我在做什么错了?
@inject(Router,HttpClientService)
export class GameMap {
constructor(router,client) {
this.client = client.client;
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.user = user;
user.getIdToken().then((idtoken) => this.client.configure(config => config.withDefaults(({headers: {'ID-TOKEN': idtoken}})))).then(() => this.requestMap());
}
});
}
requestMap() {
this.client.fetch('game').then(response => json(response)).then((data) => console.log(data))
}
}
HttpClientService
export class HttpClientService {
constructor(){
this.client = new HttpClient();
this.client.configure(config => {
config
.withBaseUrl('http://localhost:8808/')
.withInterceptor({
request(request) {
console.log(request)
console.log(`Requesting ${request.method} ${request.url}`);
return request;
},
response(response) {
console.log(`Received ${response.status} ${response.url}`);
return response;
}
});
});
}
}