【发布时间】:2017-12-17 00:12:31
【问题描述】:
我有一个父 Vue 组件,它通过一个 prop 将数据传递给它的子组件,但是数据是异步可用的,因此我的子组件使用未定义的值进行初始化。
在数据可用之前如何防止初始化?
家长:
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 方法被多次调用。
【问题讨论】:
标签: javascript asynchronous vue.js vuejs2