在vue中axios的問題

發如今vue中使用axios有一個執行多個併發請求,以前就不知道怎麼處理如今有點心得vue

function getUserAccount() {
  return axios.get('');
}

function getUserPermissions() {
  return axios.get('/api');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread((acct, perms)=>{
        //兩個都成功會走這一條
       console.log(acct, perms)
  })).catch((err)=>{
        //只要有一個失敗就會走這裏
       console.log(err) 
})    

簡單來講就是當它兩個請求都成功時纔會走then,只要有一個失敗就會走catch主要是靈活應用於不一樣的場景ios

相關文章
相關標籤/搜索