VueJs get url query

Simão Lemos picture Simão Lemos · Feb 18, 2017 · Viewed 134.6k times · Source

I'm developing a website with vuejs and at this moment I'm in a trouble, I need get the url query (page) from a url like this websitename.com/user/?page=1 but the this.$router.query.page get me a error (Uncaught TypeError: Cannot read property 'page' of undefined)

someone know something about this problem and can help me?

PS: I can set the query page using

this.$router.push({name: 'userIndex', query: { page: '123' } });

and I can get the url normal params like the

userID -> (websitename.com/user/:userId | websitename.com/user/1)

but I can't get any query parameter

Answer

Mandeep Gill picture Mandeep Gill · Feb 18, 2017

I think you can simple call like this, this will give you result value.

this.$route.query.page

Look image $route is object in Vue Instance and you can access with this keyword and next you can select object properties like above one :

enter image description here

Have a look Vue-router document for selecting queries value :

Vue Router Object