There's a couple of other ways I've found. Honestly not sure which is the best though. I really don't like importing Vue and calling prototype methods. Seems like a complete antipattern and particularly difficult when it comes to testing using localVue as the actions have been coupled to global Vue.
I'm pretty sure you're not supposed to do this but you can access the vue instance of the store from within an action using this._vm.$notify
You can create a store plugin:
const notifyStore = (store) => {
store.$notify = store._vm.$notify
}
- Create notify as a standalone module
import Vue from 'vue'
let notifier = new Vue()
export default notifier
- A combination of the two
import notifier from './notifier'
const notifyStorePlugin = (store) => {
store.$notify = notifier.$notify
}
I'm not saying this is the definitive answer on this. I'm also very open to feedback and other suggestions.
this.$notify()
. But this should apply to all plugins with instance methods. – Lobulethis
is definitely not going to work, Vuex is not an instance of Vue. Looking over the plugin it doesn't look like it gives you an easy way to do what you want. – Mehetabelwindow._app = new Vue({});
and_app.$notify({});
Thanks for the help though! – Lobule