vant、nutui、element组件库form表单的validate方法对比
vant:(https://vant-contrib.gitee.io/vant/#/zh-CN/form)[https://vant-contrib.gitee.io/vant/#/zh-CN/form]
nutui:(https://nutui.jd.com/#/zh-CN/component/form)[https://nutui.jd.com/#/zh-CN/component/form]
element:(https://element-plus.gitee.io/zh-CN/component/form.html#form-方法)[https://element-plus.gitee.io/zh-CN/component/form.html#form-方法]
vant和nutui中form表单的validate方法返回是promise
js
ref.validate().then(() => {
console.log('校验成功')
})
.catch(() => {
console.log('校验失败')
})
备注
validate()中支持传入一个或多个 name 来验证单个或部分表单项,不传入 name 时,会验证所有表单项
element中form表单的validate方法返回是function
js
this.$refs[formName].validate((valid) => {
if (valid) {
alert('submit!');
} else {
console.log('error submit!!');
return false;
}
});