Skip to content

Instantly share code, notes, and snippets.

@mrtampan
Last active January 26, 2020 18:25
Show Gist options
  • Save mrtampan/8f9a9c154f963597f3d9a2efea44e2b1 to your computer and use it in GitHub Desktop.
Save mrtampan/8f9a9c154f963597f3d9a2efea44e2b1 to your computer and use it in GitHub Desktop.
Komponen.vue full
<template>
<div>
<div class="">
<label >Username</label>
<input type="text" v-model="$v.username.$model">
<small v-if="!$v.username.required">Field is required.</small>
<small v-if="!$v.username.minLength">Username must have at least {{$v.username.$params.minLength.min}} letters</small>
</div>
<div class="">
<label >Password</label>
<input type="text" v-model="$v.password.$model">
<small v-if="!$v.password.required">Field is required.</small>
<small v-if="!$v.password.minLength">Password must have at least {{$v.password.$params.minLength.min}} letters.</small>
</div>
<div @click="submitbtn">Send Data</div>
</div>
</template>
<script>
import { required, minLength } from 'vuelidate/lib/validators'
export default {
data() {
return {
username: '',
password: ''
}
},
validations: {
username: {
required,
minLength: minLength(4)
},
password: {
required,
minLength: minLength(4)
}
},
methods: {
submitbtn() {
this.$v.touch();
if (this.$v.$error){
alert("gagal kirim")
}else{
alert("terkirim")
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment