How to pass parameters when jumping in vuejs

青灯夜游
Release: 2023-01-11 09:22:12
Original
2782 people have browsed it

Vue's method of jumping parameters: 1. Jump parameters through the params or query attribute of the router-link tag; 2. Pass "this.$router.push({name:'Route naming' ,params:{parameter name:parameter value..}})" statement to jump to transfer parameters.

How to pass parameters when jumping in vuejs

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

First create readDetail.vue and register the route in index.js.

Page delivery method:

1. Jump through router-link

<router-link>  
    <button>跳转</button> 
</router-link> 

 1. path -> 是要跳转的路由路径,也可以是路由文件里面配置的 name 值,两者都可以进行路由导航  
 2. params -> 是要传送的参数,参数可以直接key:value形式传递  
 3. query -> 是通过 url 来传递参数的同样是key:value形式传递
Copy after login

2. Jump via $router method

this. $router.push({name:'Route naming',params:{parameter name:parameter value,parameter name:parameter value}})

 this.$router.push({  
            path: 'yourPath',   
            name: '要跳转的路径的 name,在 router 文件夹下的 index.js 文件内找',  
            params: {   
                key: 'key',   
                msgKey: this.msg  
            }  
            /*query: {  
                key: 'key',   
                msgKey: this.msg  
            }*/  
        })
Copy after login

Acceptance method

  • this.$route.params.Parameter name

  • this.$route.query.Parameter name

Experiment (including two methods) :

Transmitting page:

 <router-link>
                <button>跳转</button>
              </router-link>
<button>传递</button>
-----------------------------------------------------------------------------------------
export default {
    name: 'reads',
    data () {
      return {
        msg: 'msg test.'
      }
    },
Copy after login

Receive page:

<p>
    </p><p>Num:{{ myIndex }}</p>
    <p>{{ msg }}</p>
  
-----------------------------------------------------------
data () {
      return {
        msg: '',
        // 保存传递过来的index
        myIndex: ''
      }
-----------------------------------------------------------
mounted: function () {
      this.msg = this.$route.params.msgKeyOne
      this.myIndex = this.$route.params.msgKey
      console.log(this.myIndex)
    }
Copy after login

Experiment result:

How to pass parameters when jumping in vuejs

##Related recommendations:《

vue.js tutorial

The above is the detailed content of How to pass parameters when jumping in vuejs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!