0
私は学校のためにデータを入れ子に入れました。 > fetchfetchSchoolData(schoolId) 前にあなたは、computed propertyから非同期メソッドを呼び出すことはできませんあなたがメソッドまたはウォッチャーを使用することができ、学校VueJS:完全なデータを構築するためにループ内のデータを取得する
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);
});
},
},
})
しかし、this.fetchSchoolData()ではfetchSchools()で取得できるschoolIdを知っておく必要があります – maxxdev
@ user3816475ここから 'schoolId'を取得していますが、計算から非同期メソッドを呼び出すことはできません。 – Saurabh
はい、多くの非同期クエリを持つデータを準備する方法は何ですか。例えば、 fetchSchools() - > fetchfetchSchoolData(schoolId) - > fetchSchoolDataPupuls(schoolDataId)を呼び出し、最後にデータをレンダリングします。 – maxxdev