iview 表单 验证_iview 表单验证
北京市上海市深圳市-男女提交重置export default {data () {return {formValidate: {name: '',mail: '',city: '',gender: '',interest: [],date: '',time: '',desc: ''},ruleValidate: {name: [{ required: true, messa...
北京市
上海市
深圳市
-
男
女
提交
重置
export default {
data () { return {
formValidate: {
name: '',
mail: '',
city: '',
gender: '',
interest: [],
date: '',
time: '',
desc: ''
},
ruleValidate: {
name: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
mail: [
{ required: true, message: '邮箱不能为空', trigger: 'blur' },
{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
],
city: [
{ required: true, message: '请选择城市', trigger: 'change' }
],
gender: [
{ required: true, message: '请选择性别', trigger: 'change' }
],
interest: [
{ required: true, type: 'array', min: 1, message: '至少选择一个爱好', trigger: 'change' },
{ type: 'array', max: 2, message: '最多选择两个爱好', trigger: 'change' }
],
date: [
{ required: true, type: 'date', message: '请选择日期', trigger: 'change' }
],
time: [
{ required: true, type: 'date', message: '请选择时间', trigger: 'change' }
],
desc: [
{ required: true, message: '请输入个人介绍', trigger: 'blur' },
{ type: 'string', min: 20, message: '介绍不能少于20字', trigger: 'blur' }
]
}
}
},
methods: {
handleSubmit (name) { this.$refs[name].validate((valid) => { if (valid) { this.$Message.success('提交成功!');
} else { this.$Message.error('表单验证失败!');
}
})
},
handleReset (name) { this.$refs[name].resetFields();
}
}
}
更多推荐
所有评论(0)