State or namespace.State cannot be used for data initialization
meteorlxy opened this issue · comments
Xinyu Liu commented
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.
Katashin commented
Because mapped state is defined as computed property. It is the same case that you cannot use computed property in data
function.