1. Encapsulate a js file that intercepts the request status of axios. When the status code is 404, jump to the corresponding routing page. But how do you use routing in pure js, and how does the this in this.$router () point to the instance object of vue? Is it possible to introduce vue into the current file in new?
2,
js
import Axios from "axios";
let axios_instance = Axios.create({
...
});
axios_instance.interceptors.response.use(response => {
return response
}, err => {
if (err && err.response) {
switch (err.response.status) {
case 404:
//this.$router("/error");
err.message = ",";
break;
}
}
return Promise.resolve(err.response)
});