当有两个异步函数A、B,B返回的数据是一些下拉菜单的选项什么的,A获取的是页面的数据。
A需要用B返回的数据来进行字段转义,我解决的方法是用Promise解决。
listGoodsPropertyJson(){
return new Promise(resolve => {
this.$api.XX
.xx()
.then(res => {
if (res.result == 2) {
this.$message({ message: res.msg, type: 'error' });
} else {
// 获取下拉列表
resolve(res);
}
});
});
},
A方法调用在A的异步里面
this.$api.XX.xx().then(data){
this.listGoodsPropertyJson().then(res=>{
console.log(res)// res就是这个B方法返回的数据
console.log(data)
})
}