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

116
Views
vuejs para activar uno de los 3 métodos potenciales basados en datos

Quiero activar uno de los 3 métodos según los datos que se encuentran en la subdescripción. A partir de ahora, funciona bien si los datos son "Video" y, en todo caso, activa el método myClick2. Estoy tratando de agregar una tercera opción en la que verifique si dice "Póster". Si dice poster, para activar otro método (myClicky). Cualquier otra cosa, muestra myClick2.

 new Vue({ el: "#app", data: { chocs:[] }, methods: { handleTileClick: function(){ alert("test"); }, myClick2: function(){ alert("test2"); }, myClicky: function(){ alert("tested"); }, } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <div class="card" v-on:click="choc.subdescription==='Video'?handleTileClick():myClick2()"></div> </div>

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede definir un nuevo método que acepte la subdescription y devuelva la función a llamar. Esto se usaría como un valor para el controlador de clics:

 new Vue({ el: "#app", data: () => ({ chocs: [ { subdescription: 'Video' }, { subdescription: 'Poster' }, { subdescription: 'Other' } ] }), methods: { getOnClickFn: function(subdescription) { let fn; switch(subdescription) { case 'Video': fn = this.handleTileClick; break; case 'Poster': fn = this.myClicky; break; default: fn = this.myClick2; break; } return fn; }, handleTileClick: function() { alert("test"); }, myClick2: function() { alert("test2"); }, myClicky: function() { alert("tested"); } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <div class="card" v-for="{ subdescription } in chocs" :key="subdescription" @click="() => getOnClickFn(subdescription)()" >Click {{subdescription}}</div> </div>

over 4 years ago · Santiago Trujillo 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!