最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue.js Router Query Array - Stack Overflow

programmeradmin0浏览0评论

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 0
Add a ment  | 

1 Answer 1

Reset to default 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 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.

发布评论

评论列表(0)

  1. 暂无评论