el-form只对rules中个别字段进行校验

正常属性校验方式

js 复制代码
const moveToErr = () => {
  const errorDom = document.getElementsByClassName('el-form-item__error');
  console.log(errorDom)
  if (errorDom.length) {
    errorDom[0].scrollIntoView({
      block: 'center',
      behavior: 'smooth'
    })
  }
};

const saveItem = async (formEl?: FormInstance | undefined) => {
  const newFormEl = formEl?.[0] ? formEl[0] : formEl;
  if (newFormEl) {
    const valid = await newFormEl.validate((valid, fields) => !!valid);
    if (!valid) {
      moveToErr();
      return false;
    }
  }
}

针对个别属性进行校验(validateField)

js 复制代码
const submitVideoUpload = async (formEl?: FormInstance | undefined) => {
  const newFormEl = formEl?.[0] ? formEl[0] : formEl;
  console.log(newFormEl, 'newFormEl')
  if (newFormEl) {
    const valid = await newFormEl.validateField('video', (valid, fields) => !!valid);
    if (!valid) {
      moveToErr();
      return false;
    }
  }
}
相关推荐
特创数字科技9 小时前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用
前端
IT_陈寒10 小时前
Vue的v-if和v-for混用居然是个天坑
前端·人工智能·后端
天衍四九-10 小时前
【无标题】
前端·spring boot·mysql·nginx·docker
广州华水科技10 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度
前端
xcyxiner10 小时前
DicomViewer24 修复编译bug(window test 失败)
前端·qt
linux_cfan11 小时前
videojs v10 源代码系列解读:34 · `createComposition`:类型安全的冲突检测
前端·安全
Bruce_Liuxiaowei12 小时前
网页版 DeepSeek “harness desktop“ WebGL 上下文创建失败排查实录
开发语言·javascript·webgl
utmhikari12 小时前
【AI原生】借助AI之力优化个人博客前端样式
前端·css·hexo·next·个人博客·ai-native·vibe coding
小凯在掘金12 小时前
为什么箭头函数不能作为构造函数?
前端·javascript