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

364
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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