6

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.

0

1 Answer 1

6

To 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 come 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.