1. 程式人生 > >vue路由程式設計導航

vue路由程式設計導航

1,路由歷史

加入個方法goback

<button @click="goback">後退</button>

設定方法

<script>
export default {
  name: 'app',
  methods:{
    goback(){
      this.$router.go(-1);
    }
  }
}
</script>

設定後退方法,前進為this.$router.go(1);

2、回到特定的頁面

加入方法goHome

<button @click="goHome">回到首頁</button>

設定方法

export default {
  name: 'app',
  methods:{
    goHome(){
      this.$router.push('/');
    }
  }
}