PenAndPapers
PenAndPapers

Reputation: 2108

Vue Plugin error - returns not defined

I'm currently exploring Vue JS Plugin and Im trying to create my own plugin, but after I build console returns "GlobalDataMethods is not defined". What am I missing here?

GlobalDataMethods.install = function(Vue, options) {
    Vue.getAPIData = function(paramObj) {

    }

    Vue.getFormData = function(formId) {

    }
}

Vue.use(GlobalDataMethods);

Upvotes: 0

Views: 1648

Answers (1)

Bert
Bert

Reputation: 82499

GlobalDataMethods needs to be something. You're adding an install property to GlobalDataMethods, but you never define GlobalDataMethods.

const GlobalDataMethods = {}
GlobalDataMethods.install = ...
Vue.use(GlobalDataMethods)

Consider the VueRouter plugin. The router definition is a class. The install method is added to that class.

Upvotes: 3

Related Questions