Skip to main content

Vue - V2

Turn Off Production Tip Warning

Add this to main.js

Vue.config.productionTip = false;

Use a Service Class

Create a Class

class UtilService {
constructor() {
console.log('New UtilService');
}

someFunction() {
console.log('==> someFunction called...');
}
}

export default new UtilService();

Add Class Reference to main.js

Add the class reference to Vue so we can reference the instance later in the application.

import Vue from "vue";
import UtilService from "./services/utilService";

Vue.$utilService = UtilService;
Object.defineProperty(Vue.prototype, "$utilService", {
get() {
return UtilService;
},
});

Reference the Class Instance

Vue.$utilService.someFunction();