基于elementui
在适当的el-form表单中添加规则
:rules:"rules"
然后给所需要表单规则验证的属性添加prop属性
(在el-form-item中 加上prop,然后在输入框内的输入的值和它要双向绑定)
<el-form-item label="机构代码:" :label-width="formLabelWidth" prop="code">
<el-input v-model="organization.code" autocomplete="off" :style="{width : '500px'}"></el-input>
</el-form-item>
然后在返回的data数据层中定义rules规则
//表单规则
rules: {
code: [
{
required: true,
message: "机构代码可以由英文字母和下划线组成",
validator: validatorCode,
trigger: "blur"
}
],
name: [
{
required: true, message: "请输入组织机构名称", trigger: "blur" }
],
contact: [
{
required: true,
message: "请输入联系人",
trigger: "change",
validator: validatorContact
}
],
phone: [
{
required: true,
message: "请输入正确的手机号码",
validator: validatorPhone,
trigger: "blur"
}
],
licenseUrl: [
{
required: true, message: "请输入营业许可URL", trigger: "blur" },
{
type: "url",
min: 1,
max: 1,
message: "请上传