This article describes the basic implementation method of vue routing parameters. Share it for your reference, as follows:
Preface
The use scenarios of vue route parameter transfer are generally applied when the parent route jumps to the child route, carrying parameter jumps. The transmission method can be divided intoparams
Transfer ginseng andquery
Pass the ginseng, andparams
Parameter transfer can be divided into two ways: display parameters in the url and not display parameters. These are the three ways of routing parameters by vue.
Method 1: Params parameter transfer (display parameters)
params
Parameter transfer (display parameters) can be divided into two ways: declarative and programming
1. Declarative
router-link
This method is throughrouter-link
The to attribute implementation of the component, the parameters of the method can be a string path, or an object describing the address. When passing values using this method, the subroutine needs to configure the parameters in advance, for example:
//Subrouting configuration{ path: '/child/:id', component: Child } // Parent routing component<router-link :to="/child/123">EnterChildrouting</router-link>
2. Programming
this.$
When passing values using this method, the subroutine also needs to configure parameters in advance, for example:
//Subrouting configuration{ path: '/child/:id', component: Child } //The parent route program passes parameters (usually triggered by events)this.$({ path:'/child/${id}', })
In the subroutine, you can use the following code to get the passed parameter value
this.$
Method 2: Params parameter transmission (no parameters are displayed)
params
Parameter transfer (no parameters are displayed) can also be divided into two ways: declarative and programming. The difference from the method is that this is an alias for routing.name
Passing value
1. Declarative
router-link
This method also passesrouter-link
Component's to attribute implementation, for example:
<router-link :to="{name:'Child',params:{id:123}}">EnterChildrouting</router-link>
2. Programming
this.$
When passing values using this method, the subroutine also needs to configure the parameters in advance, but it cannot be used anymore:/id
To pass the parameters, because the parent route has been usedparams
Come carry parameters, for example:
//Subrouting configuration{ path: '/child, name: 'Child', component: Child } //The parent route program passes parameters (usually triggered by events)this.$({ name:'Child', params:{ id:123 } })
In the subroutine, you can use the following code to get the passed parameter value
this.$
Note: The above useparams
The method of passing the url parameters does not display will cause the passed value to be lost when refreshing the page.
Method 3: query parameter transmission (display parameters)
query parameter transfer (display parameters) can also be divided into two ways: declarative and programming.
1. Declarative
router-link
This method also passesrouter-link
The component's to attribute implementation, but when passing values using this method, the subroutine needs to configure the routing alias (name attribute) in advance, for example:
//Subrouting configuration{ path: '/child, name: 'Child', component: Child } // Parent routing component<router-link :to="{name:'Child',query:{id:123}}">EnterChildrouting</router-link>
2. Programming
this.$
When passing values using this method, the subroutine also needs to configure the routing alias (name attribute) in advance, for example:
//Subrouting configuration{ path: '/child, name: 'Child', component: Child } //The parent route program passes parameters (usually triggered by events)this.$({ name:'Child', params:{ id:123 } })
In the subroutine, you can use the following code to get the passed parameter value
this.$
I hope this article will be helpful to everyone's programming.