9.Vue 動態(tài)設置路由參數(shù)

在vue種 可以動態(tài)設置路由參數(shù):

1.使用this.$router.go(),與js histroy.go() 用法一直,前進1,后退-1,當前頁面:0

注意 使用go時 必須是已經(jīng)有訪問歷史記錄了

案例:

  <template>
    <div>  
        <button @click="goht">后退<button> <br/>
        <button @click="goqj">前進<button> <br/>
        <button @click="gosx">刷新當前<button>
    </div>
  </template>
  <script>
    export default {
        methods: {
          goht(){
              this.$router.go(-1);
          },
          goqj(){
                this.$router.go(1);
          },
          gosx(){
              this.$router.go(0); //或者 this.$router.go(); 
          }
        }
    }
  </script>

2.使用push調(diào)用:

案例

<template>
    <div>
          <button @click="pageA">去A頁面</button>  <br/>
          <button @click="pageB">去B頁面</button>  <br/>
    </div>
</template>
<script> 
  exprot default {
    methods: {
          pageA(){
               //去路由A頁面,字符串形式只能是path,類似to="path"
              this.$router.push('/RouterA');  
          },
          pageB(){
               //去路由B頁面,數(shù)組形式,類似 :to="{}"
              this.$router.push(
                  {
                    name: 'RouterB',
                    query: {'name': 'name1', title: 'title1'}
                    //,params:{'name': 'name2', title: 'title2'}
                  }
              );
          }
     }
  }
</script>
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 1.定位 在開始運營一個微信公眾號之前可以從以下三個維度來思考定位 1.1.用戶定位:搞清楚目標用戶是誰,目標用戶...
    多多的愛閱讀 857評論 0 1
  • “男人最在意的,是兩個人在一起的狀態(tài)”“女人最糾結的,永遠是他到底愛不愛我” 1 我發(fā)現(xiàn)一個很有意思的事情,在女人...
    YIBAO閱讀 1,629評論 15 20

友情鏈接更多精彩內(nèi)容