Vue wrote a global method, but it didn't work.

I created a new global.js file under

assets/js:

import Vue from "vue";
import Router from "vue-router";

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

main.js:

//
import global from "./assets/js/global.js"
Vue.prototype.common = global

xx.vue:

<van-icon slot="right" @click="goto()"></van-icon>

methods:{
    //
    goto:function(){
        this.common.back();
    }
}

am I mistaken that the global approach doesn"t work?


solved

//
back:function(){
    window.history.go(-1);
},

this is determined by your back in this is common


back:function(){
    this.$router.go(-1);
}

this Vue

I got it wrong.

this should be the problem of this

Menu