I’m in Vue 3, I started with adding a new Vuex.Store to vue, but I continuously get this javascript error. I also tried the same thing with createStore since I use Vue 3, but it’s still the same.
What am I missing?
JavaScript
x
17
17
1
const store = new Vuex.Store({
2
modules: {
3
account: {
4
namespaced: true,
5
state: () => ({ }),
6
getters: {
7
isAdmin () { }
8
},
9
actions: {
10
login () { }
11
},
12
mutations: {
13
login () { }
14
}
15
}}
16
});
17
Than I add to Vue as store:
JavaScript
1
6
1
new Vue({
2
router,
3
store,
4
render: h => h(App),
5
}).$mount('#app');
6
What am I missing?
Complete error
JavaScript
1
12
12
1
vuex.esm-browser.js?5502:644 Uncaught TypeError: Object( ) is not a function
2
at resetStoreState (vuex.esm-browser.js?5502:644)
3
at new Store (vuex.esm-browser.js?5502:387)
4
at createStore (vuex.esm-browser.js?5502:337)
5
at eval (main.js?56d7:37)
6
at Module../src/main.js (app.js:1105)
7
at __webpack_require__ (app.js:849)
8
at fn (app.js:151)
9
at Object.1 (app.js:1118)
10
at __webpack_require__ (app.js:849)
11
at checkDeferredModules (app.js:46)
12
Advertisement
Answer
If you are using Vue 3 you need to use Vuex 4.
JavaScript
1
14
14
1
import { createStore } from 'vuex'
2
import { createApp } from 'vue'
3
4
const store = createStore({
5
state () {
6
return {
7
count: 1
8
}
9
}
10
})
11
12
const app = createApp({ /* your root component */ })
13
app.use(store)
14