chantouchsek / laravel-vue-form-validator

Laravel frontend validator
MIT License
7 stars 2 forks source link

Need more details about usage. #24

Open DasdWaller opened 3 years ago

DasdWaller commented 3 years ago

I cant understand how to use this package.

  1. Include it in Vue
    import FormValidator from 'laravel-vue-form-validator'
    Vue.use(FormValidator)
  2. after??

This my example code:

<template>
<div>
  <form @submit.prevent="login">
    <input v-model="email" type="email" name="email">
    <input v-model="password" type="password" name="password">
    <button type="submit">Log In</button>
  </form>
</div>  
</template>

<script>
import axios from 'axios'

export default {
  data () {
    return {
      email: '',
      password: ''
    }
  },

  methods: {
    login () {
      axios.post('/login').then(response => console.log(response.data))
    }
  }
};
</script>
chantouchsek commented 3 years ago

@DasdWaller okay, hang on.

chantouchsek commented 3 years ago

@DasdWaller

<template>
    <form @keydown="$errors.onKeydown($event)">
        <input type='text' v-model='name' :inputClass="errorClass"/>
        <error input="name" />
        <button @click="submit">Submit</button>
</form>
</template>
<script>

export default {
    data(){
        return{
            name: '',
            errorClass: 'form-error'
        }
    },
    methods(){
        this.$http.post('/submit', {name: this.name});
    },
     destroyed () {
       this.$errors.flush()
     }
}

</script>