I'm working on small project using nuxt js and axios and i try to put the response data in my formFields
object but i get undefined error message in the console, since i have already declared formFields
in data as you can see :
this is my code :
editCustomers (customerId, submit = false) {
this.editMode = true
this.customerId = customerId
if (submit === 1) {
// this.$Progress.start()
this.$axios.$post('mydomain.com' + customerId + '/1', $('#add-customer').serialize()).then(function (data) {
this.validation(data)
// another form validation again using the helper
this.refresh = true
})
// this.$Progress.finish()
} else {
this.$axios.$get('mydomain.com' + customerId).then(function (data) {
this.formFields = data.customers[0]
})
}
}
my data variables :
data () {
return {
laravelData: {},
formFields: {},
search: null,
editMode: true,
customerId: null,
refresh: false
}
}
as you can see i have already declared data, but when i do this.formFields = data.customers[0]
i get this error message :
Uncaught (in promise) TypeError: Cannot set property 'formFields' of undefined