4

iview表单自定义验证,提示信息不消失

 3 years ago
source link: https://segmentfault.com/a/1190000039415856
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

iview表单自定义验证,提示信息不消失

发布于 25 分钟前

iview表单自定义验证,打开子弹框后,父弹框的红色提示信息不消失,
因为父弹框没有接收到子弹框的信息;
image

解决方法

//写在data return上面的位置
const validate_dept = (rule, value, callback) => {
          value = this.addInfo.deptId || this.modifyInfo.deptId
          if (!value) {
              return callback(new Error('请选择部门'));
          } else {
              callback();
              return;
          }
      };
//规则自定义
ruleValidate: {
        deptId: [
            { required: true, validator:validate_dept, trigger:'change'}
        ]
 },

选择部门成功后的组件里需要把数据返回到父页面,父页面接收到数据后调用

 //选择部门方法
   //`deptInfo`是子弹框页面的内容
  deptInfoMethod(name) {
    this.addInfo.deptName = this.deptInfo.name;
    this.addInfo.deptId = this.deptInfo.deptId;//新增
    this.modifyInfo.deptName = this.deptInfo.name;
    this.modifyInfo.deptId = this.deptInfo.deptId;//编辑
    this.modal_dept = false;//关闭弹框
    this.$refs.addInfo.validateField('deptId');//从新校验一下规则,不然红色提示框不消失
      },

完事~


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK