pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.09k stars 1.6k forks source link

Can't abort request #670

Open rightaway opened 6 years ago

rightaway commented 6 years ago

Using the recommended approach to abort a request, it doesn't work. this.currentRequest is always null even when there is another request in progress. The strange part is that Vue devtools shows that this.currentRequest does in fact exist on the component.

If I change currentRequest to be a global variable then it works. It's the same behavior noted by someone else in https://github.com/pagekit/vue-resource/issues/38#issuecomment-136278410. Why is this.currentRequest always null? In the before function this refers to the component, so it's not that this isn't set properly.

     data() {
       return { currentRequest: null }
     },
    methods: {
       async upload(event) {
         .....
        const result = (await this.$http.post(url, formData, {
        before: request => {
            if (this.currentRequest) this.currentRequest.abort()
            this.currentRequest = request
        },