javascript - Aurelia 没有收到带有 fetch 客户端的 json 响应
问题描述
我正在尝试使用 fetch 客户端来接收包含大型数组的 json 对象。我可以在控制台中看到包含该值的承诺,但是当尝试从响应中查看数据时,它是一个空对象 {}。我究竟做错了什么?
@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;
}
});
});
}
}
解决方案
推荐阅读
- python - 运行 python 脚本时,我得到 - 而不是连字符
- linux - QProcess::用 su 命令执行
- javascript - AG-GRID 通过再次单击显示图标关闭迷你过滤器弹出窗口
- bash - 屏幕命令获取不到参数
- kubernetes - helm configmap 在 values.yaml 中包含客户端脚本
- django-filter - 如何使用 django_tables2 在同一个基于类的视图中定义两个或多个表
- mysql - 未能部署 Cloud Data Fusion“将数据从 MySQL 传输到 Google BigQuery”模板管道
- c# - 为来宾获取 Azure AD 令牌
- reactjs - AntD 表自定义过滤器功能不适用于 react 版本 15.4.2
- javascript - 一个intersectionObserver 观察多个元素或一个intersectionObserver 每个元素