我的应用程序由一个父应用程序组成,它有组件。我的目的是隔离组件,这样父组件(应用程序)和子组件(组件)之间的唯一通信是通过
然而,我有一个意外的反应性问题:当我更改子组件中的属性时,它们在父组件中也会立即得到更新。
具体来说,我会将应用程序中定义的组件数据发送给我的子组件:
<current-incident
@updated-incident="updateAllincidentsFromIncidentForm"
:currentIncident="currentIncident"
/>
currentIncident
在应用程序中定义
data()
:
data() {
return {
currentIncident: {
id: null
},
allIncidents: {},
}
},
从组件的角度来看,作为
prop
是一个对象(
props: ['currentIncident']
),然后将其分配给在其
数据()
在
mount()
组件的(
this.incident = this.currentIncident
this.incident
然后在组件中进行修改,并最终使用
this.$emit()
.
问题是家长的内容
当前事件
在我修改的时候会动态修改
incident
在组件中。
$emit()
已经发生了
.
这让我觉得
道具
通过
:currentIncident="currentIncident"
双向绑定
当前事件
,在我的理解中,这正是创建道具和发射器的原因(打破这种双向绑定)