Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Vuex Quick Start Guide

You're reading from   Vuex Quick Start Guide Centralized State Management for your Vue.js applications

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher Packt
ISBN-13 9781788999939
Length 152 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrea Koutifaris Andrea Koutifaris
Author Profile Icon Andrea Koutifaris
Andrea Koutifaris
Arrow right icon
View More author details
Toc

Enabling the Vuex built-in logger plugin

Vuex provides a built-in plugin to log every mutation. It can be added to the application store as follows:

// src/store/index.js
import createLogger from 'vuex/dist/logger';
// ...

const
debug = process.env.NODE_ENV !== 'production';
const plugins = debug ? [createLogger({})] : [];
const store = new Vuex.Store({
state: {
// ...
},
mutations,
actions,
strict: debug,
plugins,
});

The resulting output for the EveryNote app is:

Figure 4.8: Vuex built-in logger plugin

As you can see in the preceding screenshot, it logs not only the mutation name but also the previous and next state.

You can download the code at this stage by typing:

git checkout step-6_vuex-built-in-logger
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime