2

Hello there #Vue.js2 I'm encountering a problem on creating a function called in a form submit event This function needs to take 2 parameters : EVENT and ID My problem now is when I call this function i can't specify the event param without having error so my formdata and my id will be undefined in my logs. Is there any better way to handle my form ?

 updatePost(event, id) { 
  const postId = id;
  const updatedPost = new FormData(event.target); // Any way to not use event param to save this ? 
  console.log(updatedPost, postId);
},
 // Call in my Template but : 
 <form @submit.prevent="updatePost(post.id)">

ps : form composed by 2 inputs type text and 1 input type file.Vue.js screenShot

1 Answer 1

3

The original event is available as $event inside the v-on: handler.

Docs: Methods in Inline Handlers

Sometimes we also need to access the original DOM event in an inline statement handler. You can pass it into a method using the special $event variable

So this should work:

 <form @submit.prevent="updatePost($event, post.id)">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.