Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda