Vue2 router dynamically transmits parameters to instances with multiple parameters. vue2router

Source: Internet
Author: User

Vue2 router dynamically transmits parameters to instances with multiple parameters. vue2router

This is used in a project generated using vue-cli.

For example, a route jump requires two parameters:

<Router-link to = '/tr'> View </router-link>

You can write as follows:

<Router-link to = '/tr/uid/pid'> View </router-link>

Then go to router. js to process the route:

import Vue from 'vue'import Router from 'vue-router'import tr from '@/components/tr.vue'import tab from '@/components/tab.vue'Vue.use(Router)export default new Router({ routes: [ {  path:'/tr/:uid/:pid',  name: 'tr',  component:tr }, {  path:'/tab',  name: 'tab',  component:tab } ]})

You need to use vue-router in router. js, specifically in path: '/tr/: uid/: pid', add a colon after the backslash, which means the following is the route parameter.

Then the corresponding tr. vue component accepts this route parameter:

You can access this key-value object through this. $ route. params of the instance,

Let's assign a value to the request route to see:

<Router-link to = '/tr/8080'> View </router-link>

Print the following Object {uid: "15", pid: "122 "}

The above vue2 router dynamically transmits parameters. The example of multiple parameters is all the content shared by Alibaba Cloud. I hope you can provide a reference and support for the customer's house.

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.