Skip to content

Commit 49f96c4

Browse files
committed
document v-events
1 parent ae999bd commit 49f96c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/api/directives.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ Example inheriting individual properties (using the same data):
213213
</my-component>
214214
```
215215

216+
### v-events
217+
218+
- This directive can only be used with `v-component`.
219+
- This directive accepts only keypaths, no expressions.
220+
221+
Allows a parent instance to listen to events on a child instance. The difference from `v-on` is that `v-events` listens to Vue's component system events created via `vm.$emit()` rather than DOM events. This directive allows more decoupled parent-child communication without having to hard-code event listeners into the parent component. Note that it can only be used together with `v-component`, i.e. on the root element of a child component.
222+
223+
**Example:**
224+
225+
``` html
226+
<!-- inside parent template -->
227+
<div v-component="child" v-events="change: onChildChange"></div>
228+
```
229+
230+
When the child component calls `this.$emit('change', ...)`, the parent's `onChildChange` method will be invoked with additional arguments passed to `$emit()`.
231+
216232
## Literal Directives
217233

218234
> Literal directives treat their attribute value as a plain string; they do not attempt to bind themselves to anything. All they do is executing the `bind()` function with the string value once. Literal directives accept mustache expressions inside their value, but these expressions will be evaluated only once on first compile and do not react to data changes.

0 commit comments

Comments
 (0)