2017-04-05 26 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处理的第一次警报的“世界”。