Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get query parameters from a URL in Vue.js?

How can I fetch query parameters in Vue.js?

E.g. http://somesite.com?test=yay.

Can’t find a way to fetch or do I need to use pure JS or some library for this?

like image 823
Rob Avatar asked Mar 10 '16 10:03

Rob


People also ask

How do I know if a URL has a parameter query?

To check if a url has query parameters, call the indexOf() method on the url, passing it a question mark, and check if the result is not equal to -1 , e.g. url. indexOf('? ') !== -1 .


1 Answers

According to the docs of route object, you have access to a $route object from your components, which exposes what you need. In this case

//from your component console.log(this.$route.query.test) // outputs 'yay' 
like image 50
Yerko Palma Avatar answered Oct 15 '22 05:10

Yerko Palma