Vuex Tutorial: Learn State management in Vue.js using Vuex

Harish Kumar · · 4471 Views

The objective of this Vuex tutorial is to give you an essential understanding of state management in Vue.js using Vuex by creating a relatable example. By the end of this tutorial, I hope you have a better understanding of the state management using Vuex!

Vuex is the official state management library for Vue.js. Its job is to share data across the components of your application. The basic concept is derived from React’s Redux and Flux library.

Here is the video Tutorial of Vuex:

In this above video, I have used Vue.js 2 and Vuex 3. Now, the current stable version of Vue.js v3.x and Vuex v4.

And this video example also works with the current stable version (Vue 3 & Vuex 4) as well, you just need to make small following changes.

In the store.js file, we need to create a store by first importing createStore from vuex and initialize it as in the following code.

import { createStore } from "vuex";

const store = createStore({
      name: "Vue"

export default store;

Now, in the app's main.js, we need to import our store.js and use it with Vue instance, as in the following code.

import { createApp } from 'vue'
import App from './App.vue'
import store from "./store/store"

const app = createApp(App)

Learn Vuex with a simple eCommerce store tutorial:

  1. Project Setup

  2. Vuex Setup & demo API introduction

  3. Fetch products from API | Vuex State, Actions, & Mutations 

  4. Add product to cart | Vuex Getters

  5. Remove a product from the cart

  6. mapState, mapGetters, mapActions in Vuex 

  7. A smart way to use API

  8. Vuex modules & namespace

  9. Notification Component 


Please login or create new account to add your comment.

You may also like:

What is JavaScript Promise? Understanding and Implementing Promises in JS

JavaScript, the language of the web, has evolved tremendously over the years, and with it, the methods for handling asynchronous operations have improved. One such advancement (...)
Harish Kumar

JavaScript Array Destructuring: Unpacking Arrays with Ease

JavaScript array destructuring is a powerful feature introduced in ES6 (ECMAScript 2015) that simplifies the process of extracting values from arrays. It allows you to unpack an (...)
Harish Kumar

Arrow Functions: The Modern Way to Write JavaScript

JavaScript Arrow Functions, introduced in ES6 (ECMAScript 2015), have become a fundamental part of modern JavaScript development. They offer a concise and elegant way to write (...)
Harish Kumar

Essential JavaScript Tips for Better Coding - A Guide to JavaScript Best Practices

In the ever-evolving landscape of web development, the significance of JavaScript cannot be overstated. As the backbone of interactive websites, mastering JavaScript is essential (...)
Harish Kumar

From Beginner to Pro: Master JavaScript with This Comprehensive Guide (ES2015-ES2023)

Calling all aspiring and seasoned developers! I'm ecstatic to announce the release of my comprehensive eBook, "JavaScript: A Comprehensive Guide from ES2015 to ES2023". This in-depth (...)
Harish Kumar

Create SPA authentication Using Laravel Sanctum and Vue.js

In this guide, we will focus on SPA authentication in a simple Vue.js app using Laravel Sanctum. Laravel Sanctum provides a featherweight authentication system for SPAs (single (...)
Harish Kumar