Bootstrap

ElementPlus 表单验证

1.删掉script标签中的 lang='ts'

2.删掉:

import type { FormInstance } from 'element-plus'

3.改写:

const ruleFormRef = ref<FormInstance>()

为:

const ruleFormRef = ref('')

4.删掉下面代码中的 : FormInstance | undefined

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

删掉之后的:

const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
}

即可解决报错。

;