Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

712
Views
Cómo usar correctamente axios params con arreglos

¿Cómo agregar índices a la matriz en la cadena de consulta?

Intenté enviar datos como este:

 axios.get('/myController/myAction', { params: { storeIds: [1,2,3] })

Y tengo esta url:

 http://localhost/api/myController/myAction?storeIds[]=1&storeIds[]=2&storeIds[]=3

Entonces, debería obtener esta url:

 http://localhost/api/myController/myAction?storeIds[0]=1&storeIds[1]=2&storeIds[2]=3

¿Qué debo agregar en mis opciones de parámetros para obtener esta URL?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede usar paramsSerializer y serializar parámetros con https://www.npmjs.com/package/qs

 axios.get('/myController/myAction', { params: { storeIds: [1,2,3] }, paramsSerializer: params => { return qs.stringify(params) } })
over 4 years ago · Santiago Trujillo Report

0

Sin tener que agregar más bibliotecas y usando ES6, podría escribir:

 axios.get(`/myController/myAction?${[1,2,3].map((n, index) => `storeIds[${index}]=${n}`).join('&')}`);
over 4 years ago · Santiago Trujillo Report

0

Muchas gracias por la respuesta de Nicu Criste , para mi caso, la API requiere parámetros como este:

 params: { f: { key: 'abc', categories: ['a','b','c'] }, per_page: 10 }

El método es GET y esta API requiere que el formato sea: API?f[key]=abc&f[categories][]=a&f[categories][]=b... Así que asigné el paramsSerializer de axios así:

 config.paramsSerializer = p => { return qs.stringify(p, {arrayFormat: 'brackets'}) }
  • Instale qs por favor vaya a este enlace
  • Leer más sobre paramsSerializer en el documento axios
  • Edite el formato de los parámetros: lea más en qs stringifying document
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!