话不多说,先来效果图:
要求是选择延期时,延期天数必填。
<el-form-item label="是否延期" prop="status">
<el-switch
v-model="addForm.status"
active-color="#13ce66"
active-text="是"
inactive-text="否"
active-value="1"
inactive-value="0"
></el-switch>
</el-form-item>
<el-form-item label="延期天数" prop="delay" :rules="addForm.status == 1 ? rules.delay : []">
<el-input type="number" v-model="addForm.delay" placeholder="请输入延期天数"></el-input>
</el-form-item>
/***************************************************/
rules: {
delay: [{ required: true, message: "请输入延期天数", trigger: "blur" }],
}
还有一种方法可以用
<el-form-item label="延期天数" prop="delay" :required="addForm.status == 1 ? true : false">
<el-input type="number" v-model="addForm.delay" placeholder="请输入延期天数"></el-input>
</el-form-item>
敢敢单单, 套你猴子。。。