feat(Form): support async validation

This commit is contained in:
陈嘉涵
2020-02-12 10:38:05 +08:00
parent 35260e024a
commit 080d1828c8
5 changed files with 120 additions and 46 deletions
+37
View File
@@ -52,6 +52,43 @@ export default {
}
```
### Validate Rules
```html
<van-form @submit="onSubmit" @failed="onFailed">
<van-field
v-model="value"
name="phone"
label="Phone"
:rules="rules"
placeholder="Phone"
/>
<div style="margin: 16px;">
<van-button round block type="info">Submit</van-button>
</div>
</van-form>
```
```js
export default {
data() {
this.rules = [
{ required: true, message: 'Phone is required' },
{ validator: val => /1\d{10}/.test(val), message: 'Incorrect format' },
];
return { value: '' };
},
methods: {
onSubmit(values) {
console.log('submit', values);
},
onFailed(errorInfo) {
console.log('failed', errorInfo);
},
},
};
```
### Field Type - Switch
```html