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]
    }
},
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea29b6-1bf2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea29b6-1bf2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?