简体   繁体   中英

VueJS pushed new object to array, data is not reactive

This is my current data structure


days: [
  {
    id: 0
    name: 'Monday',
    times: []
  },
  {
    id: 1
    name: 'Tuesday',
    times: []
  }
}

I'm using the following method to add an object to the times array.

onTimeAdded (dayId) {
  const dayIndex = this.days.findIndex(day => day.id === dayId)
  this.days[dayIndex].times.push({ from: '09:00', to: '18:00' })
}

This adds the object to the array, but when I change the value of one of the properties of the object, it's not reactive, I define the from and to properties of the object as follows

<input
    type="time"
    name="to"
    :placeholder="To"
    :value="time.to"
>

If I add an object to a reactive array, are the properties of that object reactive?

尝试将inputvalue属性更改为v-model ,并在占位符之前删除无用的:

<input type="time" name="to" placeholder="To" v-model="time.to">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM