Skip to content

Commit ce85ca6

Browse files
committed
add section on literal vs dynamic props
1 parent 1230c00 commit ce85ca6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/guide/components.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ new Vue({
241241
</script>
242242
{% endraw %}
243243

244+
### Literal vs. Dynamic
245+
246+
A common mistake beginners tend to make is attempting to pass down a number using the literal syntax:
247+
248+
``` html
249+
<!-- this passes down a plain string "1" -->
250+
<comp some-prop="1"></comp>
251+
```
252+
253+
However, since this is a literal prop, its value is passed down a the plain string `"1"`, instead of an actual number. If we want to pass down an actual JavaScript number, we need to use the dynamic syntax to make its value be evaluated as a JavaScript expression:
254+
255+
``` html
256+
<!-- this passes down an actual number -->
257+
<comp :some-prop="1"></comp>
258+
```
259+
244260
### Prop Binding Types
245261

246262
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 flow 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 with the `.sync` and `.once` **binding type modifiers**:

0 commit comments

Comments
 (0)