You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage.md
+27-21Lines changed: 27 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -38,31 +38,37 @@ methods: {
38
38
39
39
### Cancel token
40
40
41
-
You can cancel a request using a *cancel token*.
41
+
You can cancel a request using a _cancel token_.
42
42
43
43
> The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
44
44
45
45
You can create a cancel token using the `CancelToken.source` factory as shown below:
46
46
47
47
```js
48
-
constCancelToken=this.$axios.CancelToken;
49
-
constsource=CancelToken.source();
48
+
const{ CancelToken} =this.$axios;
49
+
constsource=this.$axios.CancelToken.source();
50
50
51
-
this.$axios.$get('/user/12345', {
52
-
cancelToken:source.token
53
-
}).catch(function (thrown) {
54
-
if (this.$axios.isCancel(thrown)) {
55
-
console.log('Request canceled', thrown.message);
56
-
} else {
57
-
// handle error
58
-
}
59
-
});
60
-
61
-
this.$axios.$post('/user/12345', {
62
-
name:'new name'
63
-
}, {
64
-
cancelToken:source.token
65
-
})
51
+
this.$axios
52
+
.$get('/user/12345', {
53
+
cancelToken:source.token,
54
+
})
55
+
.catch(error=> {
56
+
if (this.$axios.isCancel(error)) {
57
+
console.log('Request canceled', error);
58
+
} else {
59
+
// handle error
60
+
}
61
+
});
62
+
63
+
this.$axios.$post(
64
+
'/user/12345',
65
+
{
66
+
name:'new name',
67
+
},
68
+
{
69
+
cancelToken:source.token,
70
+
},
71
+
);
66
72
67
73
// cancel the request (the message parameter is optional)
68
74
source.cancel('Operation canceled by the user.');
@@ -71,14 +77,14 @@ source.cancel('Operation canceled by the user.');
71
77
You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
72
78
73
79
```js
74
-
constCancelToken=this.$axios.CancelToken;
80
+
const{ CancelToken} =this.$axios;
75
81
let cancel;
76
82
77
83
this.$axios.$get('/user/12345', {
78
-
cancelToken:newCancelToken(functionexecutor(c) {
84
+
cancelToken:newCancelToken(c=> {
79
85
// An executor function receives a cancel function as a parameter
0 commit comments