vue.js - VueJS 函数与 then
问题描述
我有以下方法:
getData(id){
this.$store.dispatch('getData', {
employeeId: this.employeeId
}).then(() => {
if (this.employeeData.length) {
// here some code...
}
});
},
selectEmployee(d) {
this.getData(d.employeeId);
// I need to execute this only after getData has been processed...
this.$store.dispatch('fetchHistory');
},
所以我想做的是这样的:
selectEmployee(d) {
this.getData(d.employeeId).then(() => {
// check data here and then execute the fetch
this.$store.dispatch('fetchHistory');
});
},
但是我在then
secuence 中遇到错误,那里似乎是不允许的。
有什么线索吗?
解决方案
返回中的承诺getData
,然后您可以执行以下操作getData().then()
:
getData(id){
return this.$store.dispatch('getData', {
employeeId: this.employeeId
}).then(() => {
if (this.employeeData.length) {
// here some code...
}
});
}
推荐阅读
- python - 通过模型对象迭代 django m2m
- javascript - 如何将数据从 mysql 服务器发送到 node.js socket.io
- ios - 为什么我在swift中选择照片库时不显示照片库?
- php - 如何使用 mysql 和 php 开发足球运动员比较器?
- java - 后台失败时重启黄瓜测试
- javascript - 我该如何解决“找不到模块'./commands/${file}'”
- java - 将 Python 2D ndarray 加载到 Android 中以在 TFLite 上进行推理
- javascript - D3.js 错误:
属性变换:预期数字,“翻译(NaN,NaN)” - python - 如何在 Python 3 中加载多个 cog
- python - 使用 django 模型使用派生类的数据初始化基类