此作品针对select验证
html:
<template>
<div>
<Form ref="formInline" :model="formInline" :rules="ruleInline" :label-width="80">
<FormItem label="City" prop="city">
<Select v-model="formInline.city" style="width:200px">
<Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
</FormItem>
<FormItem>
<Button type="primary" @click="handleSubmit('formInline')">Signin</Button>
</FormItem>
</Form>
</div>
</template>
data:
cityList: [
{
value: "New York",
label: "New York"
}
],
formInline: {
city: ""
},
ruleInline: {
city: [
{
required: true,
message: "不能为空",
trigger: "change"
}
]
}
methods:
handleSubmit() {
this.$refs.formInline.validate(valid => {
if (valid) {
this.$Message.success("Success!");
} else {
this.$Message.error("Fail!");
}
});
}
注意:验证的是 :model里面的数据