V-model problem under el-table

ask everyone why I operate on arr2 under watch , and then the values of the selection box and input box cannot be changed? The code is as follows

<template>
  <div class="container">
    <div v-for="(item, index) in arr1" :key="index" >
      <el-button type="primary" @click="addArr"><span></span></el-button>
      <el-button type="primary" @click="adddata"><span></span></el-button>
      <el-table border :data="item.arr2" style="width: 400px;">
        <el-table-column label="input">
          <template slot-scope="scope">
            <el-input class="operate-input" v-model="scope.row.input" />
          </template>
        </el-table-column>
        <el-table-column label="" width="182">
          <template slot-scope="scope">
            <el-radio-group v-model="scope.row.select">
              <el-radio :label="0"></el-radio>
              <el-radio :label="1"></el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data () {
    return {
      arr1: [{arr2: []}]
    }
  },
  watch: {
    arr1: (e) => {
      e.forEach(value => {
        value.arr2.forEach(item => {
          item.input = "2"
          item.select = 1
        })
      })
    }
  },
  methods: {
    addArr () {
      this.arr1.push({arr2: []})
    },
    adddata () {
      let data = {
        value: 1,
        date: "2018-8-8"
      }
      this.arr1.forEach(item => {
        item.arr2.push(data)
      })
      this.arr1 = Array.from(this.arr1)
    }
  }
}
</script>

<style scoped>

</style>
< hr >

check whether you need to use the render function to implement two-way binding yourself. Ask for advice ~

Jul.07,2022

due to the limitation of JavaScript, Vue cannot detect arrays of the following changes:
  1. when you set an item directly using the index, for example: vm.items [indexOfItem] = newValue
  2. when you modify the length of an array, for example: vm.items.length = newLength

ide/list.html-sharp%E6%95%B0%E7%BB%84%E6%9B%B4%E6%96%B0%E6%A3%80%E6%B5%8B" rel=" nofollow noreferrer "> array update detection

Menu