Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!