Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Vue Adding/Removing Classes - Reactive Boolean vs ID

Scenario

SignalR informs a listener of changes which need reflecting on the UI. When the underlying data changes we inform non-visually impaired users of the change by adding an animation effect before removing it 3 seconds later.

Question

Which of the following 'Code Options' is considered best practice when adding/removing the animation effect? Alternatively, is there another option I've not considered which might be better? Or, should it be situational?

Personal Considerations

The 'Boolean' option feels cleaner but it's one more element being watched on a reactive object, and a lot of these are likely to change in one fell swoop. If we manually modify the DOM without using a reactive object it might save on some overhead but it doesn't feel as clean.

Code Options

Update Class on Boolean

connection
    .on("EventName", (response: ResponseModel) => {
        const foo = this.FooArray
            .find((fooDetails: FooArrayModel) => fooDetails.Id === response.Id);

        foo.Name = response.Name;
        foo.HasUpdated = true;

        setTimeout(() => {
            foo.HasUpdated = false;
        }, 3000);
    });
<div class="row">
    <template v-for="foo in FooArray" :key="foo.Id">
        <div class="cell" aria-live="polite" :class="{ 'animation-class': foo.HasUpdated }">{{foo.Name}}</div>
    </template>
</div>

Update Class on ID

connection
    .on("EventName", (response: ResponseModel) => {
        const foo = this.FooArray
            .find((fooDetails: FooArrayModel) => fooDetails.Id === response.Id);

        foo.Name = response.Name;

        const element = document.getElementById(foo.Id);
        element.classList.add("animation-class");

        setTimeout(() => {
            element.classList.remove("animation-class");
        }, 3000);
    });
<div class="row">
    <template v-for="foo in FooArray" :key="foo.Id">
        <div class="cell" aria-live="polite" :id="foo.Id">{{foo.Name}}</div>
    </template>
</div>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda