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
+23-3Lines changed: 23 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -140,15 +140,35 @@ new Vue({
140
140
141
141
<pclass="tip">It is also possible to expose `$data` as a prop. The passed in value must be an Object and will replace the component's default `$data`.</p>
142
142
143
-
#### One-Way Props
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 enforce a one-way binding that only syncs from the parent to the child by adding `*` at the beginning of the mustache:
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)
150
+
151
+
Compare the syntax:
146
152
147
153
```html
148
-
<!-- explicit one-way binding -->
154
+
<!-- default, two-way binding -->
155
+
<childmsg="{{parentMsg}}"></child>
156
+
<!-- explicit one-time binding -->
149
157
<childmsg="{{* parentMsg}}"></child>
158
+
<!-- explicit one-way-down binding -->
159
+
<childmsg="{{< parentMsg}}"></child>
160
+
<!-- explicit one-way-up binding -->
161
+
<childmsg="{{> parentMsg}}"></child>
150
162
```
151
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
+
```
169
+
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
+
152
172
In addition, if a parent prop expression is not "settable", the binding will automatically be one-way. For example:
0 commit comments