Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array from query #2701

Closed
afabros opened this Issue Apr 10, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@afabros
Copy link

afabros commented Apr 10, 2019

Version

3.0.3

Reproduction link

Steps to reproduce

https//www.websitename.com?x%5B%5D=1&x%5B%5D=2

What is expected?

this.$route.query.x[]
should return an array.

What is actually happening?

correctly inspected by browser: 
x[]: Array[2]
0: “1”
1: “2”
but when getting this array,
this line is not compiled:
this.$route.query.x[]
ERROR: Unexpected token


Is it possible to get array from this.$route.query

@afabros

This comment has been minimized.

Copy link
Author

afabros commented Apr 10, 2019

closing this issue. %5B%5D is added when name of the input is x[], but if the name of the input is only x, the vue parse the array correctly.

@afabros afabros closed this Apr 10, 2019

@afabros afabros reopened this Apr 10, 2019

@afabros

This comment has been minimized.

Copy link
Author

afabros commented Apr 10, 2019

reopening this issue. but without the %5B%5D , the server cannot recognize the server request as an array.

what is happening:
https//www.websitename.com?x[]=1&x[]=2
or
https//www.websitename.com?x%5B%5D=1&x%5B%5D=2
is seen by this.$route.query.x as undefined
but seen by server processing $_GET correctly, x is an array

while:
https//www.websitename.com?x=1&x=2
is correctly seen by this.$route.query.x as an array
but not the server processing $_GET.

@posva

This comment has been minimized.

Copy link
Member

posva commented Apr 10, 2019

that's because in PHP arrays in queries are handled differently than in browsers. You can use a custom querystringify and queryparse to adapt it to your needs (https://router.vuejs.org/api/#parsequery-stringifyquery). You can use packages like qs or query-string

@posva posva closed this Apr 10, 2019

@afabros

This comment has been minimized.

Copy link
Author

afabros commented Apr 10, 2019

what's confusing is that the array is correctly being recognized by the vue inspector on the browser, but not this.$route.query.x[] .
Screen Shot 2019-04-10 at 9 30 13 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.