ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` 方法一: //通过动态绑定rules属性和三元运算 <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> //当addForm.status的值为1时开启验证 <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" }], } ``` ``` 方法二:直接动态绑定required属性,验证是否为空 <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> ```