The data of the vue sub-component has changed. why is the view not updated?

alert can see this.info.status [index] changing with each click, but the view hasn"t changed. Why? I"ve been working on it all afternoon, and I don"t know what went wrong. That"s what my other project wrote, so I don"t know why this is so

.

state data of vuex

all: [
    {
      info: {num: [555, 666], status: [false, false]}
    },
    {
      info: {num: [555, 666], status: [false, false]}
    }
  ]

parent component

<div v-for="(item, index) in all" :key=index>
    <div class="info">
      <Info :info="item.info" :key="index"></Info>
    </div>
</div>
computed: {
    ...mapState({
      all: state => state.all
    })
}

subcomponents

<template>
 <div>
  <div v-for="(item, index) in tags" :key=index>
    <svg class="icon" aria-hidden="true" @click=change(index)>
      <use v-bind:xlink:href="info.status[index] ? item.tag2 : item.tag"></use>
    </svg>
  </div>
 </div>
</template>

<script>
export default {
  name: "Info",
  props: ["info"],
  data () {
    return {
      tags: [
        {id: 1, tag: "-sharpicon-kan1", tag2: "-sharpicon-kan2"},
        {id: 2, tag: "-sharpicon-xiao2", tag2: "-sharpicon-xiao2"}
      ]
    }
  },
  methods: {
    change (index) {
      alert(this.info.status[index])
      this.info.status[index] = !this.info.status[index]
    }
  }
}
</script>

<style scoped>
</style>
Mar.25,2022

vue cannot detect array changes in data . Use the variation methods provided by this.$set or vue to achieve array changes.

such as

const status = this.info.status[index]

this.$set(this.info.status, index, !status)

Vue.set () respond to add and modify data
at this point we need to know which parameters are needed for Vue.set (). Official API:Vue.set ()

call method: Vue.set (target, key, value)

the data source (which can be an object or an array) to be changed by target:

specific data to be changed by key:

value: reassigned value

Menu