[Vuejs]-Uncaught TypeError: Cannot set properties of undefined (setting 'lastname') – Form – Vue 3

0👍

Ok I finally found where the problem was coming from.

Here are my changes:

const contactData = ref({
  lastname: null,
  firstname: null,
  email: null,
  textarea: null,
});

const resetError = (field) => {
  if (validationErrors.value.contactForm?.[field]) {
    validationErrors.value.contactForm[field] = null;
  }
};
👤Garfaz

1👍

I think that issue might be related to default values of contactData. I would set those to strings.

const contactData = reactive({
  lastname: '',
  firstname: '',
  email: '',
  textarea: '',
});

Otherwise, I don’t see it from your snippets, but if you’re using setup() you need to return contactData for it to be available in the template.

Leave a comment