我有一个父Vue组件,它通过一个props 将数据传递给它的子组件,但数据是异步可用的,因此我的子组件使用未定义的值进行初始化.
What can I do to prevent initialization until the data is available?
Parent:
var employees = new Vue({
el: '#employees',
data: { ... },
methods: {
fetch: function(model, args=null) {
let url = "/" + model + ".json"
console.log(url);
$.ajax({
url: url,
success: ((res) => {
console.log(res)
this[model] = res;
this.isLoading = false;
error: (() => {
this.isLoading = false;
}),
complete: (() => {
// $('.loading').hide();
this.isLoading = false;
})
})
},
mounted: function() {
this.fetch(...)
this.fetch(...)
this.fetch('appointments')
}
})
我的fetch方法被多次调用.