(vue 3.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 형식 확장

import Vue from 'vue'
import Component from 'vue-class-component'

@Component
export default class InputFocus extends Vue {
  // annotate refs type.
  // The symbol `!` (definite assignment assertion)
  // is needed to get rid of compilation error.
  $refs!: {
    input: HTMLInputElement
  }

  mounted() {
    // Use `input` ref without type cast.
    this.$refs.input.focus()
  }
}


레 퍼 런 스

좋은 웹페이지 즐겨찾기