<button onclick="test()">click me</button>
<script src="https://unpkg.com/axios@0.18.0/dist/axios.js"></script>
<script>
const l = console.log;
async function test() {
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
axios("http://localhost:5000/test", {
cancelToken: source.token,
})
.then(r => {
l(r.data);
})
.catch(err => {
if (axios.isCancel(err)) {
l(err.message);
} else {
console.error(err);
// handle error
}
});
source.cancel("abort。");
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)