$router属性代替router-link

1.如不使用router-link

  <!-- <router-link to="/home" tag="button" replace>首页</router-link>  
    <router-link to="/about">关于</router-link> -->
    <button @click="homeClick">首页</button>
    <button @click="aboutClick">About</button>

2.methods中

push可以路由返回,

replace不可以

 methods:{
    // 如果不用router-link
    homeClick(){
      //通过代码的而方式修改路由 vue-router
      //push => pushState
      // this.$router.push('/home')
      this.$router.replace('/home')
    },
    aboutClick(){
    // this.$router.push('/about')
    this.$router.replace('/about')
    }
  }

 

posted @ 2021-06-28 17:13  ajaXJson  阅读(194)  评论(0编辑  收藏  举报