Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
What's the correct way to initialize a Vue app?

I'm learning Vue and have seen a lot of different sample apps, documentation and how-to's. There seem to be a number of different ways that people are initializing their components and then mounting them to their app.

My question is why are there so many ways? What's the best practice around this?

For reference I'm doing my build through npm, not through an included library in an HTML file.

Option 1

const app = new Vue({
  el: '#app',
  data: function(){
  }
});

Option 2

export default {
  name: "Test",
  data() {
    
  }
};

Option 3

const app = Vue.createApp({})

// Define a new global component called button-counter
app.component('button-counter', {
  data() {
    return {
      count: 0
    }
  }
})
app.mount('#components-demo')

Option 3 for instance comes from the Vue documentation, but when I initialize an app in that way I get an error that Vue doesn't exist.

Hoping to get some clarity for myself and any other beginner that stumbles across this question.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  • Option 1 is the Vue 2 way to create an instance.

  • Option 3 is the Vue 3 way.

  • Option 2 does not initialize a new Vue instance

The correct way to instantiate is the createApp({}) function since Vue 3. The new Vue app supported only with Vue 2.

`export default {
   name: "Test",
   data() {}
};`

The above is one way to create a component named Test. Since Vue3 alternatively you can create a component with defineComponent({}) function as well

More info -> https://v3.vuejs.org/guide/instance.html

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda