(vue3.0+)+ TypeScript ElForm 使用$refs出现异常提示,标红

提示:

Property 'validate' does not exist on type 'Vue | Element | Vue[] | Element[]'.
Property 'validate' does not exist on type 'Vue'.

个人解决方法:

import { Form as ElForm } from "element-ui";
private submitForm(formName: any) {
 (this.$refs[formName] as ElForm).validate(valid => {
    if (valid) {
      alert('submit!');
    } else {
      console.log('error submit!!');
      return false;
    }
  });
}

官方解决方法:$refs 类型扩展


参考

你可能感兴趣的:(前端,typescript,vue.js)