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

141
Views
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 answers
Answer question

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 Report

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 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!