Home > Web Front-end > Vue.js > body text

What is the difference between query and params in vue

WBOY
Release: 2022-03-17 15:30:15
Original
18717 people have browsed it

Difference: 1. Query uses path to write the parameter transfer address, while params uses name to write the parameter transfer address; 2. The parameters will not disappear when query refreshes the page, but the parameters will disappear when params refreshes the page; 3. query The passed parameters will be displayed in the URL address bar, but the params passed parameters will not be displayed in the address bar.

What is the difference between query and params in vue

The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.

What is the difference between query and params in vue

Query syntax:

this.$router.push({path:“地址”,query:{id:“123”}}); 这是传递参数
this.$route.query.id; 这是接受参数
Copy after login

params syntax:

this.$router.push({name:“地址”,params:{id:“123”}}); 这是传递参数
this.$route.params.id; 这是接受参数
Copy after login

Difference:

1 .First of all, the way of writing is different. The way of writing query is to use path to write the parameter transfer address, while the way of writing params is to use name to write the parameter transfer address. You can take a look at the relevant attributes when writing the route, and you can also output the routing object. Take a look at the information

2. The receiving methods are different, one uses query to receive, and the other uses params to receive. The summary is that whoever sends it will receive it

3.query parameters are not valid when refreshing the page will disappear, and params parameters will disappear when the page is refreshed. You can consider local storage to solve the problem.

4. The parameters passed by query are displayed in the url address bar, but the parameters passed by params will not be displayed in the address bar

【Related recommendation: "vue.js Tutorial"】

The above is the detailed content of What is the difference between query and params in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
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!