How to set the query params to URL in Vue router

How to set the query params to URL in Vue router

In this post we will give you information about How to set the query params to URL in Vue router. Hear we will give you detail about How to set the query params to URL in Vue routerAnd how to use it also give you demo for it if it is necessary.

we are going to learn about different ways to set the query params to a URL in Vue router.

Query params

The query params are added to the end of a URL using the question mark (?) followed by the key-value pairs (key=value).

Example:

localhost:3000/persons?id=1

Setting the query params

In the <route-link> component, we can set the query params to a URL using :to prop.

&lt;router-link :to="{path:'/persons',query:{id: 1}}"&gt;   Person 1&lt;/router-link&gt;

If you want to set a query params dynamically to a URL, you can use this.$router.push() method.

this.$router.push({path:'/persons', query:{id: 1}})

for multiple query params, you can pass it like this.

this.$router.push({path:'/persons', query:{id: 1, name: "john"}})

URL:

localhost:3000/persons?id=1&amp;name=john

Hope this code and post will helped you for implement How to set the query params to URL in Vue router. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US