Home  >  Article  >  Web Front-end  >  Use Vue to dynamically set routing parameters

Use Vue to dynamically set routing parameters

php中世界最好的语言
php中世界最好的语言Original
2018-06-06 11:21:541639browse

This time I will introduce to you what are the precautions for using Vue to dynamically set routing parameters. The following is a practical case, let's take a look.

1. Use this.$router.go(), the same as js history.go() The usage is always forward 1, backward -1, Current page: 0

Note that when using go, there must already be an access history record

Case:

<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. Use push call:

Case

<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>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to create pop-up box function in WeChat applet

Detailed analysis of VUE usage

The above is the detailed content of Use Vue to dynamically set routing parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn