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

367
Views
¿Cómo puedo acceder al método del componente secundario en el componente principal usando ref en Vue3?

Estoy tratando de acceder al método secundario en el componente principal utilizando el método vue3 y ref. Pero devuelve un error.

TypeError no detectado: addNewPaper.value?.savePaper no es una función

A continuación se muestra mi código. Por favor guíame donde estoy equivocado.

Componente hijo

 <script setup lang="ts"> import { useWindowScroll } from '@vueuse/core' import { Notyf } from 'notyf' import { computed, defineProps, reactive, ref } from 'vue' import { papers } from '/@src/firebase/connections' const companySize = ref('') const businessType = ref('') const productToDemo = ref('') const date = ref(new Date()) const { y } = useWindowScroll() const isStuck = computed(() => { return y.value > 30 }) const initialState = reactive({ subject: '', paper: '', marks: '', }) const notyf = new Notyf() const props = defineProps({ subjects: { required: true }, }) const savePaper = () => { papers .add(initialState) .then(() => { notyf.success('Paper saved successfully') }) .catch((err) => { notyf.error('Something went wrong') }) } </script>

Componente principal

 const addNewPaper = ref() const successSave = () => { addNewPaper.value?.savePaper() notyf.success('Your paper has been successfully created!') } <template #content> <FormAddNewTopical ref="addNewPaper" :subjects="_subjects"></FormAddNewTopical> </template>

¡Cualquier solución apreciada!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Se supone que los miembros públicos se definen con defineExpose con la sintaxis de script setup :

 defineExpose({ savePaper })

O con ctx.expose en la función de configuración :

 setup(props, ctx) { ... ctx.expose({ savePaper }) ...
about 4 years ago · Juan Pablo Isaza Report
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!