首頁  >  文章  >  web前端  >  Vue 動態設定路由參數步驟詳解

Vue 動態設定路由參數步驟詳解

php中世界最好的语言
php中世界最好的语言原創
2018-04-27 09:22:312574瀏覽

這次帶給大家Vue 動態設定路由參數步驟詳解,Vue 動態設定路由參數的注意事項有哪些,下面就是實戰案例,一起來看一下。

在vue中可以動態設定路由參數:

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

注意使用go時必須是已經有訪問歷史記錄了

案例:

<template>
  <p> 
    <button @click="goht">后退<button> <br/>
    <button @click="goqj">前进<button> <br/>
    <button @click="gosx">刷新当前<button>
  </p>
 </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呼叫:

案例

<template>
  <p>
     <button @click="pageA">去A页面</button> <br/>
     <button @click="pageB">去B页面</button> <br/>
  </p>
</template>
<script> 
 exprot default {
  methods: {
     pageA(){
        //去路由A页面,字符串形式只能是path,类似to="path"
       this.$router.push('/RouterA'); 
     },
     pageB(){
        //去路由B页面,数组形式,类似 :to="{}"
       this.$router.push(
         {
          name: 'RouterB',
          query: {'name': 'name1', title: 'title1'}
          //,params:{'name': 'name2', title: 'title2'}
         }
       );
     }
   }
 }
</script>

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

微信小程式中圖片如何自適應機型高度

如何用jquery設定用新視窗開啟外部連結

jquery圖片上傳時按指定比例預覽(附程式碼)

以上是Vue 動態設定路由參數步驟詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn