2016-12-27 47 views
2

在VueJS中重試失敗的AJAX請求的最佳方式是什麼?在vuejs中重試失敗的Ajax請求

bulkDecline(requests, decliner) { 
    requests = _.map(requests, 'id'); 
    return Vue.http.post(`${baseUrl}/api/decline/${decliner}/bulk-decline`, requests) 
    .then(
     (response) => { 
     Notification({ 
      title: 'Success!', 
      message: response.data.message, 
      type: 'success' 
     }); 
     return response; 
     }, 
     (response) => { 
     this.bulkDecline(requests, decliner); 
     } 
    ); 
} 

但它好像不工作。

+2

您可以從[這裏](http://stackoverflow.com/a/10024557/1610034)獲取靈感。 – Saurabh

回答

0

你是在一個單一文件組件中做這個嗎?

如果是這樣,你有沒有嘗試過使用

this.$http.post 

,而不是Vue.http.post

如果您通過requests發送對象{ data: requests }或類似物件,您也可能會有一些運氣。

return this.$http.post(`${baseUrl}/api/decline/${decliner}/bulk-decline`, { data: requests })