Writing Vuex Plugins
Learn how Vuex plugins work and write your own.
We'll cover the following...
Plugins are a staple of Vuex. They offer a way to provide extra functionality without shifting the responsibility to components. There are several use cases that better fit a Vuex plugin than a component. Take logging, for example, or analytics. Generally, we want data-related things to happen near the data itself, not necessarily where it is displayed. A quick search on GitHub yields 43 repositories with the tag “vuex-plugin.” A keyword search for Vuex on NPM yields roughly 1,100 packages. Most of these are plugins. The plugin API of Vuex allows us to develop all kinds of plugins. The possibilities are virtually unlimited.
How to use a plugin
Before developing, however, it’s sensible that we first learn how to install and use a plugin. While creating a store instance via the createStore
function, we can pass ...