简体   繁体   English

VueJS 将新对象推送到数组,数据不是响应式的

[英]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这将对象添加到数组中,但是当我更改对象的属性之一的值时,它不是反应性的,我定义对象的 from 和 to 属性如下

<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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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