If you follow my stories, you probably know by now that I’ve got an ongoing fight to get Vuex properly working with my Laravel Nova admin site.
A quick recap
The first iteration was to attach a Vuex Store to the
Nova global object, which works… but not an ideal one…
The second trial was to modify the Source files for Nova to access the Root creation and append my Vuex store there. (This is a viable approach if you don’t install Nova through composer). This approach was quickly deprecated by version 1.1.9 which added Vuex, and since then some parts of Nova use it as well.
After Nova 1.2 we have a modular Vuex store available on the root instace (where it’s proper place is), and is accessible through the
this.$store object! This enables us to do lots of “evil & nasty” things 😈
- You’ll need to install
vuexfor your tool / resource tool
- In your tool’s
resource/js/components/Tool.vuefile, on the
created()life cycle event, you can dynamically register your store object with
- To use the store, you can access the state through the
this.$storeobject, or (my favourite) the map helpers:
This is a future proof method because the team probably won’t remove Vuex support in the future, and this is a supported, although little know way adding modules to the Vuex store.
It’s recommended that you namespace your modules to avoid collisions with other libraries!