Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
how to write a form'data by using Class,why it give me an error "Cannot read properties of undefined (reading 'validate')"?

I'm using vue3 setup and elementUI plus,the form's validate is bothering me,the error is:"form.js?t=1640941515436:71 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'validate')".

program is ok when I write the code below:

// form.js
import { reactive, ref, unref } from 'vue'

let formRef = ref(null)
let formData = reactive(formData1)
let rules = reactive(rules1)

function valid() {
    let form = unref(formRef)
    return form.validate()
}

export { 
    formRef, 
    formData, 
    rules, 
    valid
}

// login.vue
<script setup>
import { formRef, formData, rules, valid } from './form'
const submit = async () => {
    let validResult = await valid().catch((err) => {
        return err
    })
    
    if (validResult === true) {   
    }else {
    }
}

actually I want to module the whole form,includes the html element,but is too difficult to me,so I just use Class in form.js,then I can use the Class in other file,but it throwed an error, error picture is in the end.

"Class" code:

// form.js
class Form {
    constructor(formData, rules) {
        this.formData = reactive(formData)
        this.rules = reactive(rules)
        this.formDom = ref()
    }
    valid() {
        let form = unref(this.formDom)
        return form.validate()
    }
}

export { Form } 

// Login.vue
import { Form } from './form'
let fromInstance = new Form(formData1, rules1)
const submit = async () => {
    let validResult = await fromInstance.valid().catch((err) => {
        return err
    })
    
    if (validResult === true) {
        
        
    }else {
        
    }
}

error pic

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda