[Vuejs]-How to apply watch using array in Vuejs between parents and child component

1๐Ÿ‘

โœ…

<template>
   <layout
    v-for="(value, idx) in array"
    :pickUpLength="array.length"
    :idx="idx"
    :key="idx"
   >
   <button @click="addArray">add</add>
</template>

<script>
export default {
  data() {
    array:[
      {"date" : "", "time": ""},
      {"date" : "", "time": ""}
    ]
  },
  methods:{
    addArray(newVal){
      // This is what you are doing. You can't "watch" arrays or Objects in Vue.js v2.x.x (changing in v3.x.x).
      // this.array.splice(this.array.length - 1, 0, {"yes":"no"})
      
      // This is what you have to do in this situation (based upon your comments from my original answer):
      this.array = this.array.slice(0, this.array.length - 1).concat(newVal, this.array[this.array.length - 1]);
    }
  }
};
</script>
๐Ÿ‘คth3n3wguy

Leave a comment