All requests before emptying before vue hop routing?

for example, the project is a vue-cli single-page application, so even in the jump routing, the request on the previous page will not stop, which will cause a series of problems.
found a way to cancel the request in the official document of axios, so I tried it in my encapsulated axios, but failed. Ask for advice

figure: I created an instance of axios in base.js and configured canceltoken

clipboard.png

Q: now I want to call the cancel method before each hop route (my beforeEach is in main.js)

Apr.09,2021

execute in the beforeDestoy life cycle of each component


https://github.com/axios/axio.


The

mode is wrong. It shouldn't be like this. You can write a mixin


// 
axios.interceptors.request.use(
    config => {
        // url,
        const url = config.url;
        // cancelaxios.list[url]
        config.cancelToken = new axios.CancelToken(cancel => axios.list[url] = { cancel });
        return config;
    },
    error => Promise.reject(error)
);
//axios.list,listcancel
for(let key in axios.list){
    axios.list[key].cancel();
    //
    delete axios.list[key];
}
Menu