Rumah  >  Artikel  >  hujung hadapan web  >  关于Vue 动态设置路由参数的介绍

关于Vue 动态设置路由参数的介绍

不言
不言asal
2018-06-29 17:14:071686semak imbas

这篇文章主要介绍了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(&#39;/RouterA&#39;); 
     },
     pageB(){
        //去路由B页面,数组形式,类似 :to="{}"
       this.$router.push(
         {
          name: &#39;RouterB&#39;,
          query: {&#39;name&#39;: &#39;name1&#39;, title: &#39;title1&#39;}
          //,params:{&#39;name&#39;: &#39;name2&#39;, title: &#39;title2&#39;}
         }
       );
     }
   }
 }
</script>

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

使用vuex的state状态对象的方式

基于vue cli重构多页面脚手架过程的介绍

Atas ialah kandungan terperinci 关于Vue 动态设置路由参数的介绍. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn