for example, the value of the item parameter passed to the subcomponent is 0, but the subcomponent view will report an error Cannot read property "info" of undefined "
. If you change the [this.index]
in the calculation property to [0]
, you can render the view normally, but if you write it this way, it won"t work for all lifecycles.
<template>
<div>
{{data.info}}
</div>
</template>
import { mapState } from "vuex"
data () {
return {
index: ""
}
},
computed: {
...mapState({
data: state => state.userList[this.index]
})
},
created () {
this.index = this.$route.query.item
},