Home > Blockchain >  Warning happens in Vuejs 2 when using Vuex
Warning happens in Vuejs 2 when using Vuex

Time:10-01

The warning occurs in the console when I tried to use Vuex as a store. How to remove the warning?

Below is the warning

enter image description here

Below is the package.json

enter image description here

store.js

import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex)

    export default new Vuex.Store({
        state: {
            todos: [],
            logs: []
        },
        mutations: {
            ADD_TODO(state, todo) {
                console.log('add todo work')
                state.todos.push(todo)
            },
        },
        actions: {
            addTodo({ commit }, todo) {
                commit('ADD_TODO', todo)
            }
        },
    })

main.js file

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import store from './store'

Vue.use(ElementUI);
Vue.config.productionTip = false

new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')

CodePudding user response:

You are using Vuex 4 which works with Vue 3 only. For Vue 2, you must use Vuex 3. Take a look at the note on the official Vuex documentation.

  • Related