You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/guide/components.md
+6-23Lines changed: 6 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -142,39 +142,22 @@ new Vue({
142
142
143
143
### Prop Binding Types
144
144
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:
150
146
151
147
Compare the syntax:
152
148
153
149
```html
154
-
<!-- default, two-way binding -->
150
+
<!-- default, one-way-down binding -->
155
151
<childmsg="{{parentMsg}}"></child>
152
+
<!-- explicit two-way binding -->
153
+
<childmsg="{{@ parentMsg}}"></child>
156
154
<!-- explicit one-time binding -->
157
155
<childmsg="{{* parentMsg}}"></child>
158
-
<!-- explicit one-way-down binding -->
159
-
<childmsg="{{< parentMsg}}"></child>
160
-
<!-- explicit one-way-up binding -->
161
-
<childmsg="{{> 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
-
<childmsg="{{< parentMsg}}"></child>
168
156
```
169
157
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.
173
159
174
-
```html
175
-
<!-- automatic one-way binding -->
176
-
<childmsg="{{a + b}}"></child>
177
-
```
160
+
<pclass="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>
0 commit comments