Asked By: Anonymous
I am trying to use a Vue.js plugin inside of a Vuex Store module.
In a component, I am able to call it like this: this.$plugin()
. However, in a module, this
is not set. I thought Vue.$plugin()
would work since I initialize the plugin with Vue.use(plugin)
and Vue being a global variable, but it doesn’t.
How do I reference the plugin from a module?
Solution
Answered By: Anonymous
This question was answered by Bert in the example provided here: https://codesandbox.io/s/jp4xmzl0xy
import Vue from 'vue'
import App from './App'
import Notifications from 'vue-notification'
import Vuex from "vuex"
Vue.use(Notifications)
Vue.use(Vuex)
let notifier = new Vue()
const store = new Vuex.Store({
state:{},
actions:{
notify(context, payload){
notifier.$notify(payload)
}
}
})
/* eslint-disable no-new */
new Vue({
el: '#app',
store,
template: '<App/>',
components: { App }
})