用vue写项目难免要写一个全局的back方法
methods: {
back(){
let pathes = this.$store.state.router.pathes
const length = pathes.length
const path = pathes[length-2]
if(path) {
pathes.splice(pathes.length-2, 2)
this.$router.push({ path: path.path, query: path.query })
} else {
this.$router.push('/')
}
}
}
一般的全局方法在入口main.js
加入
Vue.prototype.yourfunction = yourfunction
即可
然而路由方法,此时似乎行不通了
于是,新建一个mixins文件,全局导入,即可达到创建全局函数的目的