Element: [Bug Report] Message box can't access the Vuex store

Created on 22 Feb 2019  ·  4Comments  ·  Source: ElemeFE/element

Element UI version

2.3.8

OS/Browsers version

chrome 71.0.3578.98

Vue version

2.6.7

Reproduction Link

http://jsfiddle.net/al_sade/a2b7L4v0/25/

Steps to reproduce

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

What is Expected?

The message box should render the value coming from the store using a computed property

What is actually happening?

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.

not Element bug

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

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,
})


All 4 comments

...

@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所在的组件没有子级关系

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranzSkuffka picture FranzSkuffka  ·  3Comments

mochenxm picture mochenxm  ·  3Comments

Kingwl picture Kingwl  ·  3Comments

dbskccc picture dbskccc  ·  3Comments

no5no6 picture no5no6  ·  3Comments