pomise解决异步问题

问题:vue项目中A接口中的数据处理需要用到B接口中的数据,但axios是异步执行,导致有时B接口的数据还未返回,就开始执行A接口中的方法 

mounted() { 
2
Promise.all([this.getBuildData(), this.getTracingSourceData()]).then(this.procData) 3 } 4 methods: { 5 getBuildData() { // A接口数据 6 return request.get(`接口`) 7 .then( (data) => this.buildData = data) 8 }, 9 getTracingSourceData() { // B接口数据 10 return request.get(`接口`) 11 .then( (data) => this.tracingSourceData = data) 12 }, 13 14 procData() { // 处理两个接口的数据
15       .......
16 17 }, 18 }
原文地址:https://www.cnblogs.com/zhiqiuyiye/p/14005692.html