【发布时间】:2017-06-08 23:10:57
【问题描述】:
我已经嵌套了为学校提取数据。 生命周期看起来像 fetchSchools()->fetchfetchSchoolData(schoolId) 在渲染学校之前获取嵌套数据的最佳解决方案是什么
var app = new Vue({
el: '#app',
data: {
schools : []
},
created:function{
this.fetchSchools();
//next
this.schools = this.schools.filter(function (school) {
school.additionalData = this.fetchSchoolData(school);
return school;
})
},
methods: {
fetchSchools: function () {
var url = this.buildApiUrl('/api/schools');
this.$http.get(url).then(function (response) {
this.schools = response.data;
}).catch(function (error) {
console.log(error);
});
},
fetchSchoolData: function (school) {
var url = this.buildApiUrl('/api/school-detail?schoolId=' + school.id);
this.$http.get(url).then(function (response) {
return response.data;
}).catch(function (error) {
console.log(error);
});
},
},
})
【问题讨论】: