2.3.8
chrome 71.0.3578.98
2.6.7
http://jsfiddle.net/al_sade/a2b7L4v0/25/
create a component - 'MyCmp' ,that shows data coming from the store threw getters using a computed property.
importing 'MyCmp' component into another component that contains the message box.
pass 'MyCmp' to the messagebox message property
The message box should render the value coming from the store using a computed property
An error is received :
vue.js:634 [Vue warn]: Error in render: "TypeError: Cannot read property 'getters' of undefined".
the box is shown with any other information that's hard coded, but every dynamic data like the
computed property is missing.
...
@bar-yariv meet same problem, have solutions?
@bar-yariv just Manual inject store. because vuex auto injection is invalid in MessageBox Component.
below is the auto inject store code in vuex source code . https://github.com/vuejs/vuex/blob/dev/src/mixin.js
function vuexInit () {
const options = this.$options
// store injection
if (options.store) {
this.$store = typeof options.store === 'function'
? options.store()
: options.store
} else if (options.parent && options.parent.$store) {
this.$store = options.parent.$store
}
}
}
below is the fixed code
// component with value from the store
const store = new Vuex.Store({
})
const myCmp = Vue.component('myCmp', {
// this line inject store manually
store: store,
})
message box component 不是Vue 根组件的子节点,和store所在的组件没有子级关系
Most helpful comment
@bar-yariv just Manual inject store. because vuex auto injection is invalid in MessageBox Component.
below is the auto inject store code in vuex source code . https://github.com/vuejs/vuex/blob/dev/src/mixin.js
below is the fixed code