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

204
Vistas
vuejs how to access a ref inside a child component?

I am new to vuejs and not very experienced in JavaScript. I use Vue3 in Laravel

I have a child component which exposes a ref on an input like this

<input 
    v-model="raw_input" 
    ref="raw"  
    @input="checkLength(limit)" 
    @keydown="enterNumbers($event)" 
    type="number" 
/>

const raw = ref('');
defineExpose({
    raw
})

In the parent

<template lang="">
    <PageComponent title="Dashboard">
    <SmartVolumeInputVue ref="svi" />
    <div class="mt-16 border  h-8">
    {{ val }}
    </div>
    </PageComponent>
</template>

<script setup>
import PageComponent from "../components/PageComponent.vue"
import SmartVolumeInputVue from "../components/customInputs/SmartVolumeInput.vue";import { computed, ref } from "vue";

const svi = ref(null)
//let val=svi
//let val=svi.raw
let val=svi.raw.value
</script>

At the bottom of the script there are 3 lines (I only uncomment one at a time) The first displays this in the template

{ "raw": "[object HTMLInputElement]" }

The second displays nothing

And the third reports an error

Uncaught (in promise) TypeError: svi.raw is undefined

I need some help to get the value of the referenced input in the child component.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Do you need the ref on the element? Or only the value?

If not, just expose the value like this: Live example

// App.vue
<script setup>
import { ref } from 'vue'
import SmartVolumeInputVue from './SmartVolumeInput.vue'
const svi = ref()
</script>

<template>
    <SmartVolumeInputVue ref="svi" />
  <div>
    {{svi?.raw_input}}
  </div>
</template>
// SmartVolumeInput.vue
<script setup>
import { ref, defineExpose } from 'vue'
const raw_input = ref(123)
defineExpose({
  raw_input
})
</script>

<template>
  <input v-model.number="raw_input" type="number" />
</template>
about 4 years ago · Juan Pablo Isaza Denunciar
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