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

150
Vistas
Is there a way to select a component's prop?

I'll explain better with an example:

<template>
    <Comp prop="ex" @click.native="log" />
</template>

Having this component in my app is there a way to get the prop value from the script with something like this? (Expecting "ex" to log):

<script>
    import Comp from './components/Comp.vue'

    export default {
        components: {
            Comp
        },
        methods: {
            log() {
                console.log(Comp.prop)
            }
        }
    }
</script>

And if there is a way, does it change when having multiple instances of the same component?

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

0

In this example prop prop is hard-coded to be ex string. This value is available in Comp child but not in the parent. In order to access it in the parent, it should available in parent's state:

data() {
  return {
    compPropValue: 'ex'
  }
},
methods: {
    log(value) {
        console.log(value)
    }
}

And used like:

<Comp :prop="compPropValue" @click.native="log(compPropValue)" />
about 4 years ago · Juan Pablo Isaza Denunciar

0

It just occurred to me that I can simply pass the value that I need as a parameter of the function:

<template>
    <Comp prop="ex" @click.native="log("ex") />
</template>

<script>
    import Comp from './components/Comp.vue'

    export default {
        components: {
            Comp
        },
        methods: {
            log(s) {
                console.log(s)
            }
        }
    }
</script>

If someone knows how to actually do what I wanted it would still be helpful though!

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