Book Image

Vuex Quick Start Guide

By : Andrea Koutifaris
Book Image

Vuex Quick Start Guide

By: Andrea Koutifaris

Overview of this book

State management preserves the state of controls in a user interface. Vuex is a state management tool for Vue.js that makes the architecture easier to understand, maintain and evolve. This book is the easiest way to get started with Vuex to improve your Vue.js application architecture and overall user experience. Our book begins by explaining the problem that Vuex solves, and how it helps your applications. You will learn about the Vuex core concepts, including the Vuex store, changing application state, carrying out asynchronous operations and persisting state changes, all with an eye to scalability. You will learn how to test Vuex elements and Vue components with the Karma and Jasmine testing frameworks. You will see this in the context of a testing first approach, following the fundamentals of Test Driven Development. TDD will help you to identify which components need testing and how to test them. You will build a full Vuex application by creating the application components and services, and persist the state. Vuex comes with a plugin system that allows programmers to extend Vuex features. You will learn about some of the most powerful plugins, and make use of the built-in logger plugin. You write a custom Google Analytics plugin to send actions to its analytics API, and an Undo/Redo plugin.
Table of Contents (8 chapters)

Empowering EveryNote with two plugins

If you Google Vuex plugins, you may find various plugins for different purposes. I selected two that you will probably want to use in your next Vuex project. These plugins are:

  • vuex-persistedstate
  • vuex-router-sync

We are going to use the first one to save the EveryNote state with localStorage, so that we don't lose all the notes every time the browser page is reloaded.

It is strongly recommended that you use the second one, vuex-router-sync, if you are creating a single-page web application. In this case, you are already using vue-router and vuex-router-sync will synchronize the current route, as part of Vuex store's state.

Saving the app state with vuex-persistedstate