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

167
Views
Cómo vincular el estilo al hacer clic en un bucle

Tengo una matriz de objetos (elementos) que se pueden incrementar con otros elementos, los muestro haciendo un bucle en la matriz.

ver:

ingrese la descripción de la imagen aquí

y me gustaría resaltar un elemento cuando hago clic en él (p. ej.: otro color superior del borde), pero no puedo apuntar a un elemento específico y aplicar un estilo sin aplicar el estilo a toda la matriz. ¿Alguna idea?

Plantilla , estoy usando vuedraggable, no importa :

 <template #item="{ element }"> <div class="item" :key="element" @click=" messageItemTitle(element.title); messageItemID(element.id); " > <div class="item-title"> {{ element.title }} </div> <div class="item-subType"> {{ element.type }} </div> </div> </template>

El guión: Bueno, nada de lo que he codificado funcionó anteriormente, así que aquí están solo los datos:

 data() { return { dragItems: dragItemsList, //15 items that I can clone into dropItems dropItems: [], //Array where I can add the items from dragItems }; },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede aplicar condicionalmente la clase:

 const app = Vue.createApp({ data() { return { items: [{id:1, title: 'aaa', type: 'type1'}, {id:2, title: 'bbb', type: 'type2'}, {id:3, title: 'ccc', type: 'type3'}], selected: null }; }, methods: { message(el) { this.selected = el.id } } }) app.mount('#demo')
 .item { border: 3px solid transparent; border-top-color: black; } .selected { border-top-color: green; }
 <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script> <div id="demo"> <div v-for="(element, i) in items" :key="i"> <!--<template #item="{ element }">--> <div class="item" :class="selected === element.id && 'selected'" :key="element" @click="message(element)" > <div class="item-title"> {{ element.title }} </div> <div class="item-subType"> {{ element.type }} </div> </div> <!--</template>--> </div> </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!