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

161
Vistas
Vue js : Multiple instance VS Single instance but template from HTML, what is the best practice for performances

I have seen some questions in stackoverflow about that subject, but they never really mentioned performances.

Let's say that I have HTML page with a list of Shop, this HTML list is generated by the server in the page HTML.

I would like for each Shop HTML "block" to display a Vue JS <Calendar /> component

HTML :

<div class="list">
  <div class="shop">
    <div>
      <div>
        <div>
          <div>
           <div class="component-placeholder" data-shop-id="x"></div>
    ....
  </div>
  <div class="shop">
    <div>
      <div>
        <div>
          <div>
           <div class="component-placeholder" data-shop-id="x"></div>
    ....
  </div>
  ...
</div>

For JS there is 2 possibility.

Option 1 :

document.querySelectorAll('.component-placeholder').forEach((item) => {
  const shopId = item.getAttribute('data-shop-id');
  new Vue({
    render: (h) => h(Calendar, {
      props: {
        shopId,
      },
    }),
  }).$mount(item);
});

Option 2 :

const elem = document.querySelector('.list');
new Vue({
  el: elem,
  components: {
    Calendar
  },
});

// for this I would replace the component-placeholder with <Calendar shop-id="x" /> in the HTML

My question is, what is the best practice when focusing on performance ?

If the list has 30 Shop, Option 1 would create 30 instance of Vue living together, but Option 2 would also need to add and create all the HTML elements inside its shadow DOM when the component is first loading no ?

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