Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!