Skip to content

Commit f32499b

Browse files
committed
update binding types
1 parent 10935ad commit f32499b

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

source/guide/components.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,39 +142,22 @@ new Vue({
142142

143143
### Prop Binding Types
144144

145-
By default, all props form a two-way binding between the child property and the parent one: when the parent property updates, it will be synced down to the child, and vice-versa. However, it is also possible to explicitly enforce the following binding types:
146-
147-
- One time (only resolves once at compile time)
148-
- One way down (only sync parent changes to the child)
149-
- One way up (only sync child changes to the parent)
145+
By default, all props form a **one-way-down** binding between the child property and the parent one: when the parent property updates, it will be synced down to the child, but not the other way around. This default is meant to prevent child components from accidentally mutating the parent's state, which can make your app's data flow harder to reason about. However, it is also possible to explicitly enforce a two-way or a one-time binding:
150146

151147
Compare the syntax:
152148

153149
``` html
154-
<!-- default, two-way binding -->
150+
<!-- default, one-way-down binding -->
155151
<child msg="{{parentMsg}}"></child>
152+
<!-- explicit two-way binding -->
153+
<child msg="{{@ parentMsg}}"></child>
156154
<!-- explicit one-time binding -->
157155
<child msg="{{* parentMsg}}"></child>
158-
<!-- explicit one-way-down binding -->
159-
<child msg="{{< parentMsg}}"></child>
160-
<!-- explicit one-way-up binding -->
161-
<child msg="{{> parentMsg}}"></child>
162-
```
163-
164-
Here's a tip on understanding the direction of the arrow: the arrow indicates the direction in which the data flows between the parent property and the child property. For example:
165-
166-
``` html
167-
<child msg="{{< parentMsg}}"></child>
168156
```
169157

170-
Here we are trying to sync any changes of `parentMsg`, which is on the parent, to `msg`, which is on the child. But we don't want changes to `msg` on the child to affect the parent.
171-
172-
In addition, if a parent prop expression is not "settable", the binding will automatically be one-way. For example:
158+
The two-way binding will sync the change of child's `msg` property back to the parent's `parentMsg` property. The one-time binding, once set up, will not sync future changes between the the parent and the child.
173159

174-
``` html
175-
<!-- automatic one-way binding -->
176-
<child msg="{{a + b}}"></child>
177-
```
160+
<p class="tip">Note that if the prop being passed down is an Object or an Array, it is passed by reference. Mutating the Object or Array itself inside the child will affect parent state, regardless of the binding type you are using.</p>
178161

179162
### Passing Callbacks as Props
180163

0 commit comments

Comments
 (0)