javascript - vue3 + vee-validate - handleSubmit doesn't return values - Stack Overflow

I'm using the newest [email protected] with Composition API. I want to use current [email protecte

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:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744394423a4572068.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信