forked from cb360/we-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.vue
80 lines (70 loc) · 1.57 KB
/
index.vue
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<form @submit="onSubmitForm">
<input type="text" name="username" placeholder="用户名" />
<input type="number" name="phoneno" placeholder="手机号" />
<input type="text" name="str" placeholder="长度为3的字符串" />
<button type="default" form-type="submit">提交</button>
</form>
</template>
<script>
import WeValidator from 'we-validator'
export default {
data () {
return {};
},
methods: {
onSubmitForm (e) {
let { value } = e.target;
console.log(value);
if (!this.validatorInstance.checkData(value)) return;
// 开始提交表单
// wx.request
console.log('submiting');
},
initValidator () {
this.validatorInstance = new WeValidator({
rules: {
username: {
required: true
},
phoneno: {
required: true,
mobile: true
},
str: {
required: true,
stringLength: 3
}
},
messages: {
username: {
required: '请输入用户名'
},
phoneno: {
required: '请输入手机号',
mobile: '手机号格式不正确'
},
str: {
required: '请输入字符串',
stringLength: '字符串长度不对'
}
}
});
}
},
mounted () {
this.initValidator()
}
};
</script>
<style scoped>
input{
margin: 10px;
padding: 10px;
border: 1px solid #eee;
font-size: 16px;
}
button{
margin: 10px;
}
</style>