2017-04-05 174 views
0

使用JS庫axios,爲什麼.then/.catch部分中的代碼最終是否被渲染?axios then /在最後執行的catch代碼

save(data) { 
    axios.put('/api/persons/1', data) 
     .then(response => { 
      alert('hello') 
     }) 
     .catch(function(error) { 
      alert('goodbye') 
     }) 
    alert('world') 
} 

此功能顯示和2「你好」

+2

我建議你看看承諾/異步代碼......因爲這是對異步編程的基本理解。 .then()和.catch()將在稍後運行。 – WilomGfx

+0

謝謝@WilomGfx – Warrio

回答

1

因爲alert('world')在同一個節拍的put處理的第一次警報的「世界」。