From the course: Building Laravel and Vue.js 2 Web Apps

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Installing Vuex and managing the store

Installing Vuex and managing the store

From the course: Building Laravel and Vue.js 2 Web Apps

Start my 1-month free trial

Installing Vuex and managing the store

- [Instructor] In this video, we'll install the Vuex library and create a store, and then see how to access it from a component. So first, I'm going to open up a new host shell, and we'll run npm i, or install, save-dev vuex. And while that's installing, I'm going to create the store file in resources js. So this is going to be in store/index.js. Inside there, we'll import Vue from vue and import Vuex from vuex, so that we can set up Vuex as a plugin with Vue.use(Vuex). Now, instead of exporting an object literal, we'll export new Vuex.Store, and pass some options to that constructor, including state. State, for now, will just be a categories array and an items array. Next, we'll add a mutations key, and lets think about some of the ways that our application will need to mutate this data. When we first load the page, and Laravel is fetching the categories for us, or when we're updating the new IDs of those categories after saving, we're going to want to be able to set all of the…

Contents