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

148
Views
emitir valor desde montado en child.vue a parent.vue

Estoy trabajando con BootstrapVue .

Necesito emit un valor a mi parent.vue , pero mi línea de código this.$emit('info', this.hide); no funciona

Si console.log(this.hide) obtengo mi valor correcto en este caso falso , de lo contrario, si mi if-statement es correcta, lo obtengo verdadero .

¿Cuál es el error aquí?

guión de mi child.vue:

 data(){ return { hide: true, } } mounted() { if (statement) { if(some statement) { //do something } else { this.hide = false; console.log(this.hide); //HERE I GET CORRECT VALUE this.$emit('info', this.hide); //THIS DOESNT WORK } } }

Cómo debería funcionar en mi parent.vue:

 <template> <div @info="info"> <div> //THIS DIV SHOULD BE SHOWN IF this.hide = false </div> <div> //THIS DIV SHOULD BE SHOWN IF this.hide = true </div> </div> </template>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Idealmente en App.vue (Parent)

deberías tener algo como

 <login @info="someHandler"></login>

no hay necesidad de optar por un componente secundario si solo lo va a usar para administrar algo de lógica. Es apropiado solo si tiene algún contenido en la plantilla. También colocando el controlador de emisión en algún div. Así no es como funciona emit

A continuación se muestra un ejemplo de trabajo simple

App.vue (padre)

 <template> <h1>{{ title }}</h1> <Child @changeTitle="ChangeT($event)" /> </template> <script> import Child from "./components/Child" export default{ name:'App', components: { Child, }, data() { return{ title:'Rick Grimes' } }, methods:{ ChangeT(title) { this.title=title; }, } </script> <style></style>

niño.vue

 <template lang="html"> <button type="button" @click='passEvent'> Update me</button> </template> <script> export default { name:'Child', methods:{ passEvent() { this.$emit('changeTitle','Awesome ') } } } </script> <style lang="css" scoped> </style>
about 4 years ago · Juan Pablo Isaza Report

0

Prueba algo como el siguiente fragmento:

 Vue.component('Child', { template: ` <div class=""> child <button @click="changeHide">change hide</button> </div> `, data(){ return { hide: true, } }, methods: { changeHide() { this.hide = !this.hide this.sendInfo() }, sendInfo() { this.$emit('info', this.hide); } }, mounted() { //if (statement) { //if(some statement) { //do something //} else { this.hide = false; this.sendInfo() //} } }) new Vue({ el: '#demo', data(){ return { info: null, } }, methods: { setInfo(val) { this.info = val } } }) Vue.config.productionTip = false Vue.config.devtools = false
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="demo"> <div v-if="!info"> //THIS DIV SHOULD BE SHOWN IF this.hide = false </div> <div v-if="info"> //THIS DIV SHOULD BE SHOWN IF this.hide = true </div> <p>from child info is: {{ info }}</p> <Child @info="setInfo" /> </div>

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!