iview表单验证规则-动态新增

<base-form-line>
    <base-form-item label="开户银行:" prop="openingBank">
        <template v-if="isAdd||isEdit">
            <el-input placeholder="请输入" style="width:30rem;" v-model="formItem.openingBank"></el-input>
        </template>
        <span v-if="isInfo">{{formItem.openingBank}}</span>
    </base-form-item>
</base-form-line>
ruleValidate: any = {
...
openingBank: [],
}

//carNo为银行卡号,银行卡号有内容时,openingBank为必填

@Watch('formItem.cardNo', {
  deep: true,
  immediate: true,
})
WatchtempCardNo(data:any) {if(data) {
 this.ruleValidate['openingBank'] = [{
      required: true, message: '不能为空', trigger: 'change'
    }]
  }else{
  this.ruleValidate.openingBank = [{ required: false}]
  }
}

解决了 *号显示隐藏问题,缺点是必须触发保存按钮才能验证 ‘不能为空’的显示隐藏

上一篇:VUE Element-UI 用户修改和重置密码时,新密码和密码确认失去焦点的时候不一致的校验


下一篇:Ninja is required to load C++ extensions | 问题解决