Skip to Content
Vue.js 2 Cookbook
book

Vue.js 2 Cookbook

by Andrea Passaglia
April 2017
Intermediate to advanced
454 pages
12h 51m
English
Packt Publishing
Content preview from Vue.js 2 Cookbook

How to do it...

We will centralize the state of our whole application in a Vuex store. To install Vuex, you can add it as a dependency (more instructions at https://vuex.vuejs.org/en/installation.html); for now, I will assume that you are working on JSFiddle or a single web page, in which you can add https://unpkg.com/vuex as a dependency.

We declare a new store for our state, as follows:

const store = new Vuex.Store({})

We then add properties to the empty object inside the parenthesis, just like we would do with a Vue instance.

First, we will tell Vuex to help us debug by noticing us every time we modify the state outside of a mutation:

strict: true

Then, we will declare the state that we will use to characterize the whole system:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Vue.js 2

Learning Vue.js 2

Olga Filipova
Pro Vue.js 2

Pro Vue.js 2

Adam Freeman

Publisher Resources

ISBN: 9781786468093Supplemental Content