【发布时间】:2018-06-13 15:35:03
【问题描述】:
我有一个计算属性,只有在存在属性匹配时才会使用它。因此,我正在调用以获取数据asynchronous,以便仅在需要时检索它。我在尝试调用 async 以返回计算属性的数据时遇到问题。
以下是我所拥有的:
new Vue({
el: "#formCompleteContainer",
data: {
form: {},
components: []
},
computed: {
employeeList: function () {
var self = this;
if (_.some(this.components, function (component) {
return component.ComponentInfo.Type === 8
})) {
var employees = [];
$.ajax({
url: "/Form/GetAllUsers",
type: "GET"
}).done(function (results) {
employees = results;
});
return employees;
} else {
return [];
}
}
}
});
我知道这不起作用,因为我要在通话完成之前返回。我已经看到了如何使用 deferredobjects 以及什么没有,但我似乎无法弄清楚如何使用 Vue 来实现它。
【问题讨论】:
-
@DanielBeck 我决定不使用计算属性来做我想做的事情。但谢谢你的链接。我一定会检查一下,也许会在未来的项目中使用它。