Why did axios.interceptors execute it twice
new Vue({
router,
store,
created() {
Vue.prototype.$http = axios;
this.$http.interceptors.response.use(response => {
console.log("-----")
return response.data
}, error => {
if (error && error.response && error.response.status == "401") {
this.$cookies.remove("userName");
this.$cookies.remove("token");
//router
this.$router.options.routes = [];
this.$router.push({ path: "/login" });
}
return Promise.reject(error)
});
if (VueCookies.get("token")) {
axios.defaults.headers["Authorization"] = VueCookies.get("token");
store.dispatch("UpdateMenu");
} else {
this.$cookies.remove("userName");
this.$cookies.remove("token");
//router
this.$router.options.routes = [];
this.$router.push({ path: "/login" });
}
},
render: h => h(App)
}).$mount("-sharpapp");
printed two lines of "-". Axios.interceptors is not set elsewhere