I have API that returns json objects like this:
[
{"id":3,"delivery_from":"bsl","task_id":410169,"unit_job_id":224128,"completed_at":null,"deleted_at":null,"created_at":"2021-10-20T13:24:07.000000Z"},
{"id":3,"delivery_from":"bsl","task_id":410169,"unit_job_id":224128,"completed_at":null,"deleted_at":null,"created_at":"2021-10-20T13:24:07.000000Z"}
]
When i print response.data in browser console, I see that all objects params are ok, but when I put response.data to local array deliveryJobs: [], then I see that task_id attribute is undefined. What wrong I am doing?
<script>
import AxiosHandler from './mixins/AxiosHandler'
import axios from 'axios'
export default {
i18n: window.i18n,
mixins: [
AxiosHandler,
],
props: {
unitJobId: Number,
unitId: Number,
taskId: Number
},
data: () => ({
deliveryJobs: [],
unitJob: {}
}),
async created () {
this.getDeliveryJobs()
},
methods: {
getDeliveryJobs () {
axios
.get(`/api/v1/unitjobdelivery`, { params : { unit_job_id : this.unitJobId } })
.then(response => {
this.deliveryJobs = response.data
})
.catch(this.handleAxiosError)
}
}
}
</script>
Solution found. My API was returning laravel collection instead of array. I changed return to array and now all works fine.