1、Promise.all:
Promise .all()方法用于將多個 Promise 實例,包裝成一個新的 Promise 實例。
在處理多個異步處理時非常有用,比如說一個頁面上需要等兩個或多個ajax的數(shù)據(jù)回來以后才正常顯示。
需要特別注意的是,Promise.all獲得的成功結(jié)果的數(shù)組里面的數(shù)據(jù)順序和Promise.all接收到的數(shù)組順序是一致的。文章來源地址http://www.zghlxwxcb.cn/news/detail-536219.html
const p = Promise.all([p1, p2, p3]);
2、示例:
mounted(){
this.geAllData()
},
methods: {
//接口
robotPoseWays(coordinateNum,toolNum,unitType){
return new Promise((resolve, reject) => {
this.$base.sendRobotCMD(
{}
).then((res) => {
resolve(res.data.result)
}).catch((err) => {
});
});
},
//
geAllData(){
Promise.all([
this.robotPoseWays(parseInt(this.nowPostureNum),-1,0),
this.robotPoseWays(-1,parseInt(this.toolNumber),0)])
.then(res => {
let data ={
endCoordinate: res[0],
toolPostition: res[1]
};
record(data).then((res) => {
if (res.success) {
}
})
}).catch(err=>{
console.log('robotPoseWays',err);
})
}
},
文章來源:http://www.zghlxwxcb.cn/news/detail-536219.html
到了這里,關(guān)于vue同時請求多個接口,接口請求完成后在處理下一個方法(Promise.all用法)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!