用vue写项目难免要写一个全局的back方法
methods: {back(){let pathes = this.$store.state.router.pathesconst length = pathes.lengthconst 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
即可
然而路由方法,此时似乎行不通了
于是,新建一个minxins文件,全局导入,即可达到创建全局函数的目的