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

134
Views
Vue - Oyente de eventos de componentes dinámicos

Problema : estoy tratando de crear un componente de table para mi aplicación que otros componentes utilizarían para representar una tabla. Podría tener tres posibles valores de celda:

  • Texto
  • HTML
  • Componente

Puedo representar todos los valores anteriores, pero estoy atascado al vincular un detector de event . Lo que estoy tratando de lograr es algo como esto: pase un método y un evento que se vinculará al componente y la tabla debería vincularlo con la celda respectiva. Así por ejemplo :

TABLA JSON

 { "cell-1":{ "type":"html", "data":"<h4>text-1</h4>", "method": someMethod } }

COMPONENTE DE MESA

 <tbody> <template> <tr> <td > <span v-if="type == 'html'" v-html="data" v-on:click.native="$emit(someMethod)" v-on:click.native="someMethod" ></span> </td> </tr> </template> </tbody>

Arriba hay solo un fragmento de lo que estoy intentando, la tabla recorre el objeto pasado y se representa en consecuencia.

ya he probado

  • SO Solución 1
  • SO Solución 2

Por favor, hágamelo saber si se requiere más información.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La mejor manera es tener el método/controlador dentro del componente principal y luego el disparador está usando la funcionalidad de emisión de tal manera que en

COMPONENTE DE MESA

 <tbody> <template> <tr> <td > <span v-if="type == 'html'" v-html="data" v-on:click.native="$emit('trigger-handler', {method: 'method1', data: {}})" ></span> </td> </tr> </template> </tbody>

y en

Padre.vue

 <table-component @trigger-handler="triggerHandler" />

guion interior

 export default { data() { }, methods: { triggerHandler(payload) { // payload is actually the object passed from the child this[payload.method](payload.data); // call a specific method }, method1(data) { }, method2(data) { }, method3(data) { } } }
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!