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

365
Visualizações
Vue.prototype vs Vue.use vs import for each file

These are some of the ways I know to create a global function to vue js project:

time.js

// if Vue.use()

export default {
  install: Vue => {
    Object.defineProperty(Vue.prototype, "time", {
       return new Date().getTime();
    })
  }
}

// else 

function time () {
  return new Date().getTime();
}

export { time }

main.js

...

import { time } from "time";

// if Vue.prototyp
Vue.prototype.$time = time 

// else if Vue.use()
Vue.use(time)

...

App.vue

// if Vue.prototype or Vue.use()
console.log(this.$time());

// else 
import { time } from "time";
console.log(time());

What is the best method for vue js project?

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

0

Use import rather than polluting the global scope.
You will not benefit from tree-shaking, will probably have collisions, it's harder to debug and probably some other drawbacks that I cannot think about right now.

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