vue-router: Array in query is not correct while pushed
Vue.js / vue-router versions
2.3
Reproduction Link
https://jsfiddle.net/KingMario/gnk3a044/
Steps to reproduce
Click the “Push Url” button, then click any link.
What is Expected?
The url should be https://fiddle.jshell.net/KingMario/gnk3a044/show/#/foo?x[]=1&x[]=2
What is actually happening?
Get https://fiddle.jshell.net/KingMario/gnk3a044/show/#/foo?x=1&x=2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 15 (5 by maintainers)
step:
url: /list
js: router.push({query: {a:[1]}}) // url: /list?a=1
refresh chrome
js: console.log(route.query.a) // 1, expected: [1]
On address bar not didn’t do the difference between new Array(1) and string
@posva
expected: $route.query.x = [1] ,but: $route.query.x = 1 ,this is the key @posva
Soo if I want to access the parameter from php, for example after a page refresh, it will not act as an array of items? Edit: Yeah, it just overrides all with the last parameter.
In the future, we will provide a way of overwriting the query parser with a custom one like qs
OK so workaround I thought of is to send a comma separated list of values and explode that on the server. To still be able to use the value with v-model and a checkbox for example I did a computed property with a setter and getter as follows:
Now we can just use
arrayItemwithv-modelin our templates.no, you actually have
[1]: https://jsfiddle.net/posva/gnk3a044/1/it’s just a valid choice. You can use a different syntax by plugging in qs (check queryParser at https://router.vuejs.org/en/api/options.html )
On Mon, Nov 6, 2017 at 11:51 AM Andy notifications@github.com wrote:
–
Eduardo San Martin Morote