promise.all 發送多個請求


 getInfo() {
        // 創建promise,在promise中調用axios then里使用resolve回調,catch里使用reject回調
      var p1 = new Promise((resolve, reject) => {
          this.$axios.get(httpUrl.getUser).then(res=>{
              resolve(res)
          }).catch(err=>{
              reject(err)
          })
      });

      var p2 = new Promise((resolve,reject)=>{
          this.$axios.get(httpUrl.getCompany).then(res=>{
              resolve(res)
          }).catch(err=>{
              reject(err)
          })
      })

    // 調用Promise.all().then(res=>{})
      Promise.all([p1,p2]).then(res=>{
          console.log(res);
          
      })
    }
  },



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM