The problem of getting parameters by vue sub-components

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
},
May.16,2022

the this.index in your initialization index='',computed is'', and the returned data value is undefined,mounted before index changes


<template>
  <div>
    {{data.info || ''}}
  </div>
</template>
import { mapState } from 'vuex'

data () {
    return {
      index: this.$route.query.item,
      data: {}
    }
},
computed: {
    ...mapState(['userList'])
},
created () {
    if(this.userList[this.index]){
        this.data = this.userList[this.index]
    }
},
Menu