forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15FormValidation.txt
56 lines (52 loc) · 1.72 KB
/
15FormValidation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Make a component and import in App.vue
Make some fields
Make function for submit a function
Add error validation
1) Make a component
- src/components/Login.vue:
<template>
<div>
<p v-if="error.length">
<b>Please correct the following errors</b>
<ul>
<li v-for="e in error" v-bind:key="e.id">{{e}}</li>
</ul>
</p>
<form @submit="login">
<input type="text" placeholder="enter name" v-model="name" /> <br><br>
<input type="password" placeholder="enter password" v-model="password" /> <br><br>
<button v-on:click="loginData" type="submit">Login</button>
</form>
</div>
</template>
<script>
export default {
name: 'Login',
data(){
return{
error:[],
username:null,
password:null,
}
},
methods:{
login(e){
this.error=[];
if(this.name && this.password)
{
console.warn("No error")
}
if(!this.name)
{
this.error.push("Name is required")
}
if(!this.password)
{
this.error.push("Password is required")
}
console.warn("Hello",this.error)
e.preventDefault();
}
}
}
- import this component in App.vue