Vue-resource: how to cancel a request while the request has been send

Created on 9 Jun 2017  路  2Comments  路  Source: pagekit/vue-resource

I want to find a way to cancel request after it is sent.
my status: I want to cancel a uploading file, so I must to stop this request.
I look a lot of pages , only I can find is stop before request.
It is not suitable for me.
ive been stuck for more than 3 days looking for an answer...

Most helpful comment

You should be able to do that based on the https://github.com/pagekit/vue-resource/blob/master/docs/recipes.md#abort-a-request recipe. A reference to the last request is stored on your component:

    before(request) {
      // set previous request on Vue instance
      this.previousRequest = request;
    }

so just add a new method to cancel the request:

  methods: {
    cancelUpload: function () {
        this.previousRequest.abort();
    }
  }

and a button that calls this method.

All 2 comments

You should be able to do that based on the https://github.com/pagekit/vue-resource/blob/master/docs/recipes.md#abort-a-request recipe. A reference to the last request is stored on your component:

    before(request) {
      // set previous request on Vue instance
      this.previousRequest = request;
    }

so just add a new method to cancel the request:

  methods: {
    cancelUpload: function () {
        this.previousRequest.abort();
    }
  }

and a button that calls this method.

You solved my problem.
@danmichaelo 锛寉ou are so nice. thx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gbhlwm picture gbhlwm  路  5Comments

nivv picture nivv  路  4Comments

Jigsaw5279 picture Jigsaw5279  路  5Comments

santigraviano picture santigraviano  路  5Comments

odranoelBR picture odranoelBR  路  6Comments