1

I need to pass the array using vue http get. But I not sure how to do so.I know I can pass parameter for get method using (I am using spatie/laravel-query-builder) '/users?filter[name]=John'.

I have an array of category = [10, 20, 100]; the contain of category is id. I need to pass the id to laravel controller.

vue.js to call get

axios.get(url).then((res) => {
  console.log(res.data);
})
.catch((err) => console.error(err));
Peter Kota
  • 8,048
  • 5
  • 25
  • 51
Firdaus
  • 143
  • 5
  • 22
  • Possible duplicate of [pass array as parameter in an axios request](https://stackoverflow.com/questions/49682409/pass-array-as-parameter-in-an-axios-request) – Rehan Feb 19 '19 at 04:06

1 Answers1

1

You need to JSON.stringify the passed data and assign this string to a get parameter (in this example: myArray).

const data = [{ id: 1 }, { id: 2 }]
const url = 'https://myendpoint.com'

axios.get(url, {
  params: {
    myArray: JSON.stringify(data)
  }
}).then(res => console.log(res))
Peter Kota
  • 8,048
  • 5
  • 25
  • 51