1

I have a vue component sending a form to backend and getting JSON code. Then it set some data to show/hide messages on the template.

But... I got an undefined error:

"TypeError: Cannot set property 'sent' of undefined"

Which means "this" not exists anymore. Why?

    export default {
    name: "contactsComponent",

    data: function(){

        return {
            sent: false,
            sentError: false,
            error: false,
        }
    },

    methods: {
        sendContact: async (e) => {
            e.preventDefault();
            const dataForm = serialize("contactForm");
            const {data} = await poRepository.sendContact(dataForm);
            console.log(data);
            this.sent = true;
            this.sentError = data.error;
         },
     }
  }
Uncoke
  • 1,832
  • 4
  • 26
  • 58

0 Answers0