Global guard of VueRouter, how to get Vue instance

in fact, I want to do login verification in the hook function beforeEach, and this login verification will call the background interface, but I can"t get the instance of vm in this hook function, so I can"t get the token, in store and I can"t request the backend. After messing around all morning, I really can"t find a solution, so I can only ask you for advice

.

related codes

Router.vue
<script>
    import Vue from "vue"
    import VueRouter from "vue-router"
    Vue.use(VueRouter)
    import Api from "@/components/config/Api"
    import home from "@/pages/index"
    import login from "@/pages/login"
    import info from "@/pages/info"

    const router = new VueRouter({
        routes: [{
            path: "/",
            name: "index",
            component: home
        },{
            path: "/login",
            name: "login",
            component: login
        },{
            path: "/info",
            name: "info",
            component: info
        }],  
    });
    
    router.beforeEach((from, to, next) => {
        this.$http.get(Api.is_login_uri,{params: {"1":this.$store.state.token}}).then(function(res){
            let code = res.data.code;
            if(code != "0"){
                next({path:"/info",params:{"msg":res.data.data}});
            }
        },function(error){
            next({path:"/info",params:{"msg":""}});
        });
    })

    export default router;
</script>
Code of main.js
import router from "./components/config/Router"
import store from "./components/config/Store"

//  pages  Home.vue 
//import index from "./pages/index"

//  Vue *
var vm = new Vue({
  el: "-sharpapp",
  router,
  store,
  data(){
    return {
    }
  },
  created(){
    document.title=this.Global.appName;
  }
})
Mar.29,2021

const vm = Vue.prototype;
print the vm to see if you can get those vue messages.


you introduce your store.js into the routing router.js to try


change the way of thinking, and introduce store into the router.js. Why not?

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-1e49430-44cfa.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-1e49430-44cfa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?