Ask Your Question
0

How can I get the values returned from handleSubmit in vue3 with vee-validate?

asked 2022-01-08 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-25 01:00:00 +0000

lalupa gravatar image

To get the values returned from handleSubmit in Vue 3 with vee-validate, you can use the "values" property returned by the handleSubmit function. The "values" property contains an object with the names of the input fields as keys and their corresponding values as values.

Here's an example:

<template>
  <form @submit.prevent="submitForm">
    <label>
      Name:
      <input type="text" v-model="name" v-validate="'required'">
    </label>
    <label>
      Email:
      <input type="email" v-model="email" v-validate="'required|email'">
    </label>
    <button type="submit">Submit</button>
  </form>
</template>

<script>
import { useForm } from '@vee-validate/core'

export default {
  setup() {
    const { handleSubmit, values } = useForm()

    const submitForm = handleSubmit(formData => {
      console.log(formData) // prints an object with the input field values
      console.log(values) // also prints the same object with the input field values
    })

    return {
      submitForm
    }
  }
}
</script>
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-08 11:00:00 +0000

Seen: 8 times

Last updated: Feb 25 '22