[Vuejs]-Type of event during form submit in vuejs?

0👍

This is a typescript error. You can explicitly give it an any type. Or give it an actual type. Or change your typescript settings to allow implicit any.

const handleFormSubmit = (event:any) => {
    event.preventDefault();

    const email = event.target.elements.email?.value;
    const password = event.target.elements.password?.value;

    console.log(email, password);
};

-1👍

I tried casting the event.target as HTMLInputElement as suggested here, but I still got complaints for missing parameters. I ended up doing this in the end

async function newPlayer(event: Event) {
  event.preventDefault();
  const form = event.target as HTMLFormElement;
  const formData = new FormData(form);
  console.log(formData.get("name"))
}
👤Tzane

Leave a comment