文章来源地址https://www.toymoban.com/news/detail-647111.html
上代码
<el-form-item label="出库单号" prop="ecode" ref="ecode" :rules="rules.ecode">
<el-input v-model="queryParams.ecode" placeholder="出库单号和出库箱号至少填写一项" clearable style="width: 300px" />
</el-form-item>
<el-form-item label="出库箱号" prop="econtainerCode" ref="econtainerCode" :rules="rules.econtainerCode">
<el-input v-model="queryParams.econtainerCode" placeholder="出库单号和出库箱号至少填写一项" clearable style="width: 300px" />
</el-form-item>
data() {
var validateName = (rule, value, callback) => {
if (!this.queryParams.ecode && !this.queryParams.econtainerCode) {
callback(new Error("请至少填写一项"))
} else {
//任意值被填写,清除验证提示
if (!this.queryParams.ecode || !this.queryParams.econtainerCode) {
// this.$nextTick(() => {
// this.$refs.zhname.clearValidate()
// })
this.$refs.ecode.clearValidate()
this.$refs.econtainerCode.clearValidate()
}
callback()
}
}
return {
rules: {
ecode: [
{
required: true,
validator: validateName,
trigger: "change",
},
],
econtainerCode: [
{
required: true,
validator: validateName,
trigger: "change",
},
],
}}
原文来源
文章来源:https://www.toymoban.com/news/detail-647111.html
到了这里,关于VUE+ElementUI的表单验证二选一必填项,并且满足条件后清除表单验证提示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!