If you want to access your Vue instance, simply use this._vm;
To access the Vue global, you can do so by using import Vue from 'vue';
and then calling Vue;
It seems like you have defined an instance method, in that case, you would use the former syntax (this._vm.plugin1method()
)
update
I cannot recommend a specific way of using it without seeing how your function is defined within your plugin.
However, let me provide an example to demonstrate the distinction between instance and global:
const myPlugin = {
install: function(Vue, options) {
// 1. add global method or property
Vue.myGlobalMethod = function() {
// some logic ...
console.log("run myGlobalMethod");
};
Vue.mixin({
methods: {
plugin1method(key, placeholderValues = []) {
console.log("run mixin method");
return key;
}
}
});
// 4. add an instance method
Vue.prototype.$myMethod = function(methodOptions) {
console.log("run MyMethod");
// some logic ...
};
}
};
Vue.use(Vuex);
Vue.use(myPlugin);
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
this._vm.$myMethod();
Vue.myGlobalMethod();
this._vm.$options.methods.plugin1method(); // <-- plugin mixin custom method
state.count++;
}
}
});
When you trigger the increment with this.$store.commit('increment')
, both methods will be executed