Authored by yyq

promise all

... ... @@ -264,33 +264,23 @@ export default {
},
load() {
this.listPreCache = {};
return new Promise(resolve => {
let resNum = 0;
const apis = [
this.fetchTopicSimpleInfo({topicId: this.topicId}).then(res => {
if (res.code === 200) {
this.setPageShareInfo(get(res, 'data', {}));
}
if (!get(res, 'data.topicImageUrl')) {
this.headerAnimateStep = 100;
}
}),
this.fetchTopicRelatedArticles({topicId: this.topicId, page: 1}).then(res => {
if (res.code === 200) {
this.listPreCache[`${this.topicId}-1`] = res;
}
})
];
return Promise.all([
this.fetchTopicSimpleInfo({topicId: this.topicId}).then(res => {
if (res.code === 200) {
this.setPageShareInfo(get(res, 'data', {}));
}
apis.forEach(api => {
api.then(() => {
if (++resNum >= apis.length) {
resolve();
}
});
});
});
if (!get(res, 'data.topicImageUrl')) {
this.headerAnimateStep = 100;
}
}),
this.fetchTopicRelatedArticles({topicId: this.topicId, page: 1}).then(res => {
if (res.code === 200) {
this.listPreCache[`${this.topicId}-1`] = res;
}
})
]);
},
async onFetch() {
const topicId = parseInt(this.topicId, 10);
... ...