可以使用:
vue-router的beforeRouterEnter钩子
其实也就是一个路由守卫
<script>
export default {data() {return {fromPath: "",};},beforeRouteEnter(to, from, next) {next((vm) => {// 通过 `vm` 访问组件实例,将值传入fromPathvm.fromPath = from.path;console.log(to)console.log(from)});},methods: {goBack() {this.$router.push({path: this.fromPath,});},},
};
</script>