Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Created August 14, 2017 14:25
Show Gist options
  • Save Kelin2025/afffd1f9334b86a73271f0991532fb92 to your computer and use it in GitHub Desktop.
Save Kelin2025/afffd1f9334b86a73271f0991532fb92 to your computer and use it in GitHub Desktop.
Vuelidate-apicase-connect example
<template>
<form @submit.prevent="$form('testForm').submit('hello')">
<h2> Vuelidate-forms + Vue-Apicase demo</h2>
<label> My name is </label>
<input
type="text"
v-model="test.name"
@input="$v.test.name.$touch"
:class="{ invalid: $v.test.name.$invalid && $v.test.name.$dirty }"
placeholder="Enter your name"
>
<div class="text-grey" v-if="apis.hello.pending"> Wait please</div>
<button v-else> Enter </button>
</form>
</template>
<script>
import { required } from 'vuelidate/lib/validators'
export default {
forms: {
test: {
name: {
required,
$value: 'Noname'
}
}
},
api: {
hello: {
hooks: {
// Successful submit
success (ctx) {
console.log(`Hello, ${ctx.query.name}!`)
},
// If validation failed
validationFailed () {
console.log('Validation failed')
},
// Another error happened
error () {
console.log('It\'s a disaster!')
}
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment