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

Rob picture Rob · Mar 10, 2016 · Viewed 269.7k times · Source

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?

Answer

Yerko Palma picture Yerko Palma · Mar 10, 2016

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'