Skip to content
Permalink
Browse files
fix(plugin): hide progress-bar on cancelled requests (#398)
  • Loading branch information
T0shik committed Aug 3, 2020
1 parent 669d969 commit 206172133e8cf3e8dc4f28efe34da695f2cb64f4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
@@ -161,6 +161,10 @@ const setupProgress = (axios) => {
currentRequests--

if (Axios.isCancel(error)) {
if (currentRequests <= 0) {
currentRequests = 0
$loading().finish()
}
return
}

@@ -1,6 +1,17 @@
function sleep (ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

module.exports = {
path: '/test_api',
handler (req, res) {
async handler (req, res) {
const query = new URL(req.url, 'http://localhost:3000').query
if (query && query.delay) {
await sleep(query.delay)
}

res.end(JSON.stringify({
url: req.url,
method: req.method
@@ -0,0 +1,33 @@
<template>
<div>
there should be no loading bar left over:
<button @click="test">Fake Request</button>
</div>
</template>

<script>
export default {
methods: {
test() {
const source = this.$axios.CancelToken.source();
this.$axios
.$post(
"http://localhost:3000/test_api/foo/bar?delay=1000",
{ data: "test" },
{
cancelToken: source.token,
}
)
.catch((err) => {
if (this.$axios.isCancel(err)) {
console.log("request canceled");
}
});
setTimeout(function () {
source.cancel();
}, 500);
},
},
};
</script>

0 comments on commit 2061721

Please sign in to comment.