最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Object(...) is not a function for Vuex Store - Stack Overflow

programmeradmin7浏览0评论

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?

const store = new Vuex.Store({
    modules: {
    account: {
    namespaced: true,
    state: () => ({  }), 
    getters: {
        isAdmin () {  } 
    },
    actions: {
        login () {  } 
    },
    mutations: {
        login () {  } 
    }
 }}
});  

Than I add to Vue as store:

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

What am I missing?

Complete error

vuex.esm-browser.js?5502:644 Uncaught TypeError: Object(...) is not a function
at resetStoreState (vuex.esm-browser.js?5502:644)
at new Store (vuex.esm-browser.js?5502:387)
at createStore (vuex.esm-browser.js?5502:337)
at eval (main.js?56d7:37)
at Module../src/main.js (app.js:1105)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at Object.1 (app.js:1118)
at __webpack_require__ (app.js:849)
at checkDeferredModules (app.js:46)

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?

const store = new Vuex.Store({
    modules: {
    account: {
    namespaced: true,
    state: () => ({  }), 
    getters: {
        isAdmin () {  } 
    },
    actions: {
        login () {  } 
    },
    mutations: {
        login () {  } 
    }
 }}
});  

Than I add to Vue as store:

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

What am I missing?

Complete error

vuex.esm-browser.js?5502:644 Uncaught TypeError: Object(...) is not a function
at resetStoreState (vuex.esm-browser.js?5502:644)
at new Store (vuex.esm-browser.js?5502:387)
at createStore (vuex.esm-browser.js?5502:337)
at eval (main.js?56d7:37)
at Module../src/main.js (app.js:1105)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at Object.1 (app.js:1118)
at __webpack_require__ (app.js:849)
at checkDeferredModules (app.js:46)
Share Improve this question edited Oct 27, 2020 at 11:09 tolga asked Oct 27, 2020 at 11:04 tolgatolga 2,8105 gold badges41 silver badges74 bronze badges 2
  • Can you post the plete error with stack trace? – deceze Commented Oct 27, 2020 at 11:08
  • I added the plete error. – tolga Commented Oct 27, 2020 at 11:10
Add a ment  | 

2 Answers 2

Reset to default 10

If you are using Vue 3 you need to use Vuex 4.

import { createStore } from 'vuex'
import { createApp } from 'vue'

const store = createStore({
  state () {
    return {
      count: 1
    }
  }
})

const app = createApp({ /* your root ponent */ })
app.use(store)

https://vuex.vuejs/guide/#vuex-4-x-for-vue-3

npm uninstall vuex
npm install [email protected]
//  Convert version to 3.4.0 Can perfectly solve this problem 
发布评论

评论列表(0)

  1. 暂无评论