From 3d0280e65a27c1534c3f81ba667b589af3b4138a Mon Sep 17 00:00:00 2001 From: Bharath B Date: Wed, 30 May 2018 21:49:02 +0530 Subject: [PATCH] Usage with Vuex Update documentation to provide examples for usage with Vuex --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index c0100a3..fff656b 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,43 @@ export default { ``` + +## With Vuex +```javascript +import Vue from 'vue' +import App from './App' +import Notify from 'vue-notifyjs'; +import Vuex from "vuex" + +Vue.use(Notify) +Vue.use(Vuex) + +let notifier = new Vue() + +const store = new Vuex.Store({ + state:{}, + actions:{ + notify(context, payload){ + notifier.$notify(payload) + } + } +}) + +new Vue({ + el: '#app', + store, + template: '', + components: { App } +}) + +``` +Now you can dispatch an action like so +```javascript +this.$store.dispatch('notify', { + message: 'Welcome!', + type: 'success', + }); +``` **Note:** `` can be declared only once anywhere in your app, preferably in your root component so the notification component is alive inside any other components.