Skip to content

Commit 7ba9b2e

Browse files
committed
Add documentation on @emit
1 parent ad09353 commit 7ba9b2e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs-source/book/essential/components.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,38 @@ In that case, you must cast $event to it's type, so that Vue GWT knows what type
536536
</div>
537537
```
538538

539+
#### `@Emit` annotation {#emit-annotation}
540+
541+
If you want a method to automatically emit an event each time it's called you can also use the `@Emit` annotation.
542+
It works similarly to the one from [vue-property-decorator](https://github.com/kaorun343/vue-property-decorator).
543+
544+
```java
545+
@Component
546+
public class EmitAnnotationComponent extends VueComponent {
547+
@Emit
548+
@JsMethod
549+
public void doSomething() {
550+
DomGlobal.console.log("Doing something");
551+
// Implicit call to this.$emit("do-something")
552+
}
553+
554+
@Emit
555+
@JsMethod
556+
public void doSomethingWithValue(int value) {
557+
DomGlobal.console.log("Doing something with a value");
558+
// Implicit call to this.$emit("do-something-with-value", value)
559+
}
560+
561+
562+
@Emit("custom-event-name")
563+
@JsMethod
564+
public void doSomethingWithValueAndCustomName(int value) {
565+
DomGlobal.console.log("Doing something");
566+
// Implicit call to this.$emit("custom-event-name", value)
567+
}
568+
}
569+
```
570+
539571
#### Binding Native Events to Components
540572

541573
There may be times when you want to listen for a native event on the root element of a component.

0 commit comments

Comments
 (0)