vue: [Vue 2.0] [Vuex] Cannot create property mergeHook on string 'beforeCreate'

This issue is kinda the same as #4544, but i’ve got it working now.

When you have (multiple) components in components, and they all use store (vuex) in the following way:

import storeName from 'storeFile'

export default {
  store: storeName,
  methods: {
    // your methods
  }
}

it will result in an error some times (not always) and only in Chrome (on my computer, not on my colleagues computer with same browser, etc), not in Safari. (Mac OS X Yosemite)

Error:

TypeError: Cannot create property 'function mergeHook(
  parentVal,
  childVal
) {
  return childVal
    ? parentVal
      ? parentVal.concat(childVal)
      : Array.isArray(childVal)
        ? childVal
        : [childVal]
    : parentVal
}' on string 'beforeCreate'
    at mergeField (eval at <anonymous> (app.js:606), <anonymous>:1169:18)
    at mergeOptions (eval at <anonymous> (app.js:606), <anonymous>:1160:5)
    at resolveConstructorOptions (eval at <anonymous> (app.js:606), <anonymous>:3329:32)
    at createComponent (eval at <anonymous> (app.js:606), <anonymous>:2391:3)
    at _createElement (eval at <anonymous> (app.js:606), <anonymous>:2864:15)
    at Proxy.render (eval at <anonymous> (app.js:3090), <anonymous>:91:7)
    at VueComponent.Vue._render (eval at <anonymous> (app.js:606), <anonymous>:2954:22)
    at VueComponent.eval (eval at <anonymous> (app.js:606), <anonymous>:2191:21)
    at Watcher.get (eval at <anonymous> (app.js:606), <anonymous>:1656:27)
    at new Watcher (eval at <anonymous> (app.js:606), <anonymous>:1648:12)

I think it is trying to “merge” (mergeHook (?)) the property’s (including store) with his parent component.

I’m not 100% sure that this is the issue, but I have changed every store: storeName to the data:

export default {
  data () {
    return {
      'store': storeName
    };
  },

  methods: {
  }
}

And everything works now. But when I change everything back to store: storeName (property on the same level as data, methods, computed, etc… it will throw the error again.

I hope this is helpfull, and if people have the same issue they should try this to solve it.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (4 by maintainers)

Most upvoted comments

What you’re looking for are modules: https://vuex.vuejs.org/en/modules.html Create only one store and split it into multiple modules