ktsn / vuex-class

Binding helpers for Vuex and vue-class-component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

State or namespace.State cannot be used for data initialization

meteorlxy opened this issue · comments

Example:

import { Component, Vue } from 'vue-property-decorator'
import { State } from 'vuex-class'

@Component
export default class App extends Vue {
  @State('hello') hello

  helloFromVuexClassState: string = this.hello
  helloFromVuexState: string = this.$store.state.hello
}
  • this.$store.state.hello works well

  • this.hello from @State('hello') cannot work. Error msg:

[Vue warn]: Property or method "helloFromVuexClassState" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Repro repo:
https://github.com/meteorlxy/vuex-class-repro/blob/88cf65573dd53cd5b9c62128ab1fba66abae481e/src/App.vue#L21-L27

Because mapped state is defined as computed property. It is the same case that you cannot use computed property in data function.