The method of passing parameters between vue-router2.0 components and obtaining dynamic parameters, vue-router2.0

Source: Internet
Author: User

The method of passing parameters between vue-router2.0 components and obtaining dynamic parameters, vue-router2.0

1. Tag

<li v-for=" el in hotLins" >  <router-link :to="{path:'details',query: {id:el.tog_line_id}}">        

2. When you need to pass dynamic parameters in a component, the example above can be used.

<router-link :to="{path:'details',query: {id:el.tog_line_id}}">

3. The parameter id in the query is the parameter to be passed in. The method obtained in the component is:

created: function() {  var id = this.$route.query.id;  this.getData(id); },

4. As mentioned above, this. $ route. query. id can be used to obtain this parameter, or this. $ root. id = id; can be used to pass the parameter to the parent component.

// Root component constructor var vm = Vue. extend ({router: router, data: function () {return {id: '000000' // city event details id }}});

5. Define the id in data, and then use props to pass the parameter in the child component.

props: {    id: {     type: String,     required: true    }   },

6. In router-view, pass this parameter:

<router-view :id="id" :order-info="orderInfo"></router-view>

Note that order-info is used here.

The above vue-router2.0 components between passing parameters and obtain dynamic parameters is small make up to share with you all the content, hope to give you a reference, also hope you can support a lot of help home.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.