Passing parameters through the params of the Vue attribute $route

不言
Release: 2018-07-09 14:20:14
Original
13366 people have browsed it

This article mainly introduces the params passing through the Vue attribute $route. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

vue passing value Passing parameters with vue are two different things

Concept diagram

Passing parameters through the params of the Vue attribute $routePrinciple

The principle of vue passing parameters mainly lies in Vue.$route.params (also $route.query)

$route is the attribute of Vue, params is the attribute of $route, use To store key-value pairs of data (object form, {key:value}), store many attributes (key-value pairs, attributes, attribute values) in it.

List:

By browsing Using the vue devtools plug-in (vue developer tool plug-in), you can see the specific data inside the $route attribute:
Passing parameters through the params of the Vue attribute $route$route.params, **It can be said that $route is an intermediate container**, used to Accommodating parameters is a key-value pair method. In this way, when you execute an action on this page and pass the parameters to $route.params, you can get the parameters from $route.params on another page. That's it.

Definition in routing

//router >> index.js { path: '/Page9/:abc/:cde', name: 'Page9', component: Page9 }
Copy after login

It means that I want to store the attributes "abc" and "cde" in Vue.$route.params, which are used as attribute names and key names,

The attribute value is determined by the change of the path triggered after clicking on the route. Just write whatever you want to transmit, for example

//App.vue  点击就跳转到page9,并同时传参到Vue.$route.params 
Copy after login
//Page9.vue  
Copy after login

means that in the end Vue.$route.params will store { "abc" : "gigi" ,"cde" : "lkjdk7338"}
Passing parameters through the params of the Vue attribute $route

Or use programming routing to write the parameters to be passed in the script js :
html:

Copy after login

js:

sj1() { this.$router.push({ path: '/Page9', name: 'Page9', params: { abc: this.mydata, cde: 'dlj' } })
Copy after login

It means that in the end Vue.$route.params will store the data {"abc" : this.mydata, "cde" : ' 'dlj''}

How to get the value:
This is very simple:
Just get it directly from Vue.$route.params
{{ $route.params.abc }} --> "gigi" or the specific value of this.mydata

{{ $route.params.abc }} --> " lkjdk7338 "

The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

vue-router nginx non-root path configuration method

How vue solves the problem of adding routes dynamically with addRoutes The problem of post-refresh failure

The above is the detailed content of Passing parameters through the params of the Vue attribute $route. 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
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!