简体   繁体   中英

How do I create an instance for this package with Vue?

I'm trying to use this logging package I found in my Vue Project. https://github.com/xpl/ololog

I want to be able to use the logger in my whole project and all my components. Do I have to import the package in every single component I want to use it in or is there a way to make it global?

How can I make an instance for it? Sorry, I am confused about this. Thank you.

You can either:

A. Import the logger on every component

B. Add an instance property to make the log function accessible to all components:

// When you initialize your Vue app
Vue.prototype.$log = myLogFunction

// Now $log is available on all Vue instances via `this`
this.$log("my log");

A is more explicit, B is more convenient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM