我有一个 Obj1 数组。在项目 vue 3+ts 中,单击“加载更多”按钮后,我通过 axios 调用后端服务并检索相同类型的数组。我想将此行附加到前一个数组,但它不起作用:
this.Array1.push(response.data)
如果我当时添加 1 个项目,则 Array1 会更新:
this.Array1.push(response.data[0])
我错过了什么?
我有一个 Obj1 数组。在项目 vue 3+ts 中,单击“加载更多”按钮后,我通过 axios 调用后端服务并检索相同类型的数组。我想将此行附加到前一个数组,但它不起作用:
this.Array1.push(response.data)
如果我当时添加 1 个项目,则 Array1 会更新:
this.Array1.push(response.data[0])
我错过了什么?
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)
你在推动不同的价值观。response.data.results 是一个数组,而 response.data 是一个带有数组的 json 数据。
因此,您可能只想这样做:
this.Array1 = response.data.results