I'm trying to do is pass an array from query to the backend using Vue.js and router.
So I have this method:
submitForm () {
this.$router.push({
name: 'AuctionResult',
query: {
models: this.selectedModels.map(e => e.value)
}
})
},
As a result will be query like this: ?models=MODEL1&models=MODEL2...
But how can I make inputs look like array, like this: ?models[]=MODEL1&models[]=MODEL2...
???
I didn`t find anything in the documentation.
I'm trying to do is pass an array from query to the backend using Vue.js and router.
So I have this method:
submitForm () {
this.$router.push({
name: 'AuctionResult',
query: {
models: this.selectedModels.map(e => e.value)
}
})
},
As a result will be query like this: ?models=MODEL1&models=MODEL2...
But how can I make inputs look like array, like this: ?models[]=MODEL1&models[]=MODEL2...
???
I didn`t find anything in the documentation.
Share Improve this question edited Feb 11, 2019 at 16:30 Pierce O'Neill 38310 silver badges24 bronze badges asked Jun 5, 2018 at 4:31 Dmitry MalysDmitry Malys 1,3234 gold badges26 silver badges51 bronze badges 01 Answer
Reset to default 6To support PHP / array style multi-values, you can just set the key name to be what you want, ie
query: {
'models[]': this.selectedModels.map(e => e.value)
}
This may e out as
?model%5B%5D=MODEL1&model%5B%5D=MODEL2...
but that's fine (it's just URL encoded) and your server-side request handler should decode it correctly.