2016-12-27 94 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 })