Hello everyone! In this article, I am going to share with you my approach for creating and managing a global store in Vue 3 without Vuex.

Required skills: Vue, JavaScript, TypeScript

Advantages:
1. No Vuex (extra dependency)
2. Compatible with a new Composition API
3. Similar to Vuex syntax, so you don't need to get used to something new😄
5. Typed

Let's start.

@/store/index.ts

import auth from "./modules/auth";import { Store } from "./types";const store: Store = { modules: { auth } };export function commit<T>(
moduleName: string,
mutation: string,
payload?: T
) {
const foundModule = store.modules![moduleName];

Oleksii Shaposhnikov

Front-end Vue developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store