Does the vue encapsulate the fallback function to report an error?

fallback is a common function, so I encapsulated it as a global function

//assetes/global.js
import Vue from "vue"
import Router from "vue-router";
Vue.use(Router)

export default({
    //
    back:function(){
        this.$router.go(-1); //
    },
})

error message is Cannot read property "go" of undefined

so I wrote it differently:

Router.$router.go(-1);

still report an error, how to solve it?


you can call the method


//main.jsVUE
window.VUE = new Vue({
  el: '-sharpapp',
  router,
  store,
  components: { App },
  template: '<App/>'
})
//assetes/global.jsback
VUE.$router.go(-1);
only if you refer to the Router instantiated by your project through new .
Menu