vuejs / vuex-router-sync

Effortlessly keep vue-router and vuex store in sync.
MIT License
2.52k stars 125 forks source link

Uncaught TypeError: store.registerModule is not a function #62

Closed ghost closed 7 years ago

ghost commented 7 years ago

I just create a new project from vue-cli. And I get this error when try to add vuex-router-sync

index.js?7e73:4 Uncaught TypeError: store.registerModule is not a function
    at exports.sync (eval at <anonymous> (app.js:2927), <anonymous>:4:9)
    at eval (eval at <anonymous> (app.js:1512), <anonymous>:23:26)
    at Object.<anonymous> (app.js:1512)
    at __webpack_require__ (app.js:660)
    at fn (app.js:86)
    at Object.<anonymous> (app.js:2966)
    at __webpack_require__ (app.js:660)
    at app.js:709
    at app.js:712

main.js

import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import { sync } from 'vuex-router-sync'

sync(store, router, { moduleName: 'RouteModule' })

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})

store

import Vuex from 'vuex'
import Vue from 'vue'
import home from './home.js'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    home
  }
})

export default {
  store
}
ghost commented 7 years ago

My mistake. I was exporting plain object store and I should export Vuex.

export default new Vuex.Store({
  modules: {
    home
  }
})