Vue は同時に複数のインターフェースをリクエストし、インターフェースリクエストが完了した後に次のメソッドが処理されます (Promise.all の使用)

1、約束.すべて:

Promise.all() メソッドは、複数の Promise インスタンスを新しい Promise インスタンスにラップするために使用されます。
これは、複数の非同期処理を扱う場合に非常に役立ちます。たとえば、ページ上に複数の ajax データが戻ってくるのを待ってから正常に表示する必要があります。
Promise.all によって取得された成功結果の配列内のデータの順序は、Promise.all によって受信された配列の順序と一致していることに注意することが重要です。

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);
                })
     }
},

おすすめ

転載: blog.csdn.net/weixin_43883951/article/details/129861895