Skip to content

Commit ac5ec65

Browse files
committed
document prop binding types
1 parent dddb6f2 commit ac5ec65

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

source/guide/components.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,35 @@ new Vue({
140140

141141
<p class="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>
142142

143-
#### One-Way Props
143+
### 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 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:
146152

147153
``` html
148-
<!-- explicit one-way binding -->
154+
<!-- default, two-way binding -->
155+
<child msg="{{parentMsg}}"></child>
156+
<!-- explicit one-time binding -->
149157
<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>
150162
```
151163

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>
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+
152172
In addition, if a parent prop expression is not "settable", the binding will automatically be one-way. For example:
153173

154174
``` html

0 commit comments

Comments
 (0)