Vue how to use vuerouter to jump in the newly created axios.js interceptor file

the newly created http.js sets the interceptor. How to determine if you are not logged in in the request interceptor, and then use vue-router to jump to the login page

import axios from "axios"
import { Message } from "element-ui"
import Router from "vue-router"

axios.interceptors.request.use(function (config) {
    // 
    console.log("")
    Router.push("/login")//
    return config;
}, function (error) {
    // 
    Message.error({message: "", duration: 2000})
    return Promise.reject(error);
});

report an error like this

Mar.23,2021

create a new routing instance in the routing file router.js

//router.js
const router = new vueRouter({
    routes,
    mode: 'history',
    base: __dirname,
    ...
});
...
export default router;

introduce router where routing is needed

//axios.js
import router from 'router.js';
router.push(link);

it doesn't work here. Use window.location.href to jump


main.js file
const rootVueObj = new Vue ({

router: router,
render: h => h(App),

}). $mount ('- sharpapp');
export default rootVueObj;

api file
import rootVueObj from'. / main.js';
use rootVueObj instead of this in interceptor


Axios is not suitable for unlogged-in redirects
if the best way to judge unlogged-in redirects is

import router from './router'

router.beforeEach((to, from, next) => {
  if (getToken()) { // token
      // 
    } else {
      next('/login') // 
    }
  }
})

axios.interceptors.response.use (
response = > {

)
 if(response.data.code == "-999"){
    layer.msg(",")
     localStorage.clear();
     store.dispatch("add2")
     store.dispatch("del1")
     router.push({path: "/login"})
 }
return response;

},
error = > {

  return Promise.reject(error)

});

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e47d18-6527e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e47d18-6527e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?