I have an array of Obj1. In a project vue 3 ts , after clicking the button "load more", i call via axios the backend service and retrive an array of the same type. I want to append this rows to the previous array, but it is not working :
this.Array1.push(response.data)
If i add 1 item at the time, the Array1 gets updated:
this.Array1.push(response.data[0])
What am i missing?
CodePudding user response:
Based on your question that this code works:
this.Array1.push(response.data.results[0])
Indicates that response.data.results
is the array you want to work with. If you want to push that entire array in, you can simply use the ES6 spread operator:
this.Array1.push(...response.data.results)
CodePudding user response:
You're pushing different values. response.data.results is an array, while response.data is a json data with an array.
So, you might want to just do:
this.Array1 = response.data.results