[Vuejs]-How do I my App.vue page to the Vuex store?

0👍

You should install vuex 4 which it’s compatible with vue 3 using the following command :

npm i vuex@next

then create your store as follows :

import { createApp } from "vue";
import App from "./App.vue";
import { createStore } from "vuex";

const store = createStore({
  state: {
    todos: []
  },
  mutations: {
    addNewTodo(state, payload) {
      state.todos.push(payload);
    }
  },
  actions: {},
  getters: {
    getTodos(state) {
      return state.todos;
    }
  }
});

let app = createApp(App);
app.use(store);
app.mount("#app");

Leave a comment