Typescript in vue - Property 'validate' does not exist on type 'Vue | Element | Vue[] | Element[]'.

后端 未结 5 1756
感动是毒
感动是毒 2020-12-23 17:38

I created v-form like this


  ...
  

        
5条回答
  •  伪装坚强ぢ
    2020-12-23 18:04

    If you use vue-class-component with vue-property-decorator you can do it like this:

    Define in a types.ts a new Type with the vuetify form functions:

    export type VForm = Vue & {
      validate: () => boolean;
      resetValidation: () => boolean;
      reset: () => void;
    };
    

    Then import in your component:

    import { VForm } from "types";
    import { Component, Ref} from "vue-property-decorator";
    

    Use @Ref in your component to define the form:

    export default class YourComponent extends Vue {
      @Ref("form") readonly form!: VForm;
    }
    

    so in your methods you can use it like this:

    this.form.validate();
    this.form.resetValidation();
    this.form.reset();
    

提交回复
热议问题