admin管理员组

文章数量:1403527

I'm using the newest [email protected] with Composition API. I want to use current [email protected] accordingly to their documentation. But when handleSubmit is used nothing works as I expect.

<form @submit="onSubmit">
  <div class="mb-3">
    <label for="edit-email" class="form-label">E-mail</label>
    <input
      id="edit-email"
      name="email"
      class="form-control"
      v-model="email"
      type="text"
      />
    <div class="invalid-feedback">{{ emailError }}</div>
  </div> 

  <button class="btn btn-primary" type="submit">Save</button> 
</form>
import { useField, useForm } from "vee-validate";
import { object, string } from "yup";

export default {
  name: "App",
  setup() {
    const { handleSubmit } = useForm();

    const onSubmit = handleSubmit((values) => { 
      console.log(values, submitCount.value); // values is empty: {}
    });

    const schema = object({
      email: string().required().email(),
    });

    useForm({
      validationSchema: schema,
      initialValues: {
        email: "",
      },
    });

    const { value: email, errorMessage: emailError } = useField("email");

    return {
      email,
      emailError, 
      onSubmit,
    };
  },
};

Reproduced problem:

本文标签: javascriptvue3veevalidatehandleSubmit doesn39t return valuesStack Overflow