其他分享
首页 > 其他分享> > iview表单验证规则-动态新增

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}]
  }
}

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

标签:验证,ruleValidate,required,表单,openingBank,formItem,true,any,iview
来源: https://blog.csdn.net/qq_25103439/article/details/121970439