File tree 3 files changed +49
-1
lines changed
3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,10 @@ const setupProgress = (axios) => {
161
161
currentRequests --
162
162
163
163
if ( Axios . isCancel ( error ) ) {
164
+ if ( currentRequests <= 0 ) {
165
+ currentRequests = 0
166
+ $loading ( ) . finish ( )
167
+ }
164
168
return
165
169
}
166
170
Original file line number Diff line number Diff line change
1
+ function sleep ( ms ) {
2
+ return new Promise ( ( resolve ) => {
3
+ setTimeout ( resolve , ms )
4
+ } )
5
+ }
6
+
1
7
module . exports = {
2
8
path : '/test_api' ,
3
- handler ( req , res ) {
9
+ async handler ( req , res ) {
10
+ const query = new URL ( req . url , 'http://localhost:3000' ) . query
11
+ if ( query && query . delay ) {
12
+ await sleep ( query . delay )
13
+ }
14
+
4
15
res . end ( JSON . stringify ( {
5
16
url : req . url ,
6
17
method : req . method
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div >
3
+ there should be no loading bar left over:
4
+ <button @click =" test" >Fake Request</button >
5
+ </div >
6
+ </template >
7
+
8
+ <script >
9
+ export default {
10
+ methods: {
11
+ test () {
12
+ const source = this .$axios .CancelToken .source ();
13
+ this .$axios
14
+ .$post (
15
+ " http://localhost:3000/test_api/foo/bar?delay=1000" ,
16
+ { data: " test" },
17
+ {
18
+ cancelToken: source .token ,
19
+ }
20
+ )
21
+ .catch ((err ) => {
22
+ if (this .$axios .isCancel (err)) {
23
+ console .log (" request canceled" );
24
+ }
25
+ });
26
+
27
+ setTimeout (function () {
28
+ source .cancel ();
29
+ }, 500 );
30
+ },
31
+ },
32
+ };
33
+ </script >
You can’t perform that action at this time.
0 commit comments