From a5e4052e98e753dc3f7042c5d180c6105c6c3245 Mon Sep 17 00:00:00 2001 From: Barney Szabolcs Date: Tue, 12 Apr 2022 00:40:16 +0200 Subject: [PATCH 1/2] Update events.md Added more explanation to modifiers that require a native event, otherwise generating surprising error messages. --- src/v2/guide/events.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/v2/guide/events.md b/src/v2/guide/events.md index ede0254df2..9c5df2c6ef 100644 --- a/src/v2/guide/events.md +++ b/src/v2/guide/events.md @@ -178,6 +178,12 @@ To address this problem, Vue provides **event modifiers** for `v-on`. Recall tha - `.passive` ``` html +Please note that with the exception of `.once` the modifiers above only work with **native events**. + +

+When emitting native-looking events from components, such as 'click', it is a good practice to also emit the native event. eg. `this.$emit('click', {...data, ...event})`. If you haven't read about components yet, don't worry about this for now. +

+ From 99c84f00d6d185d43a1546bd88432c23d43c48d9 Mon Sep 17 00:00:00 2001 From: Barney Szabolcs Date: Tue, 12 Apr 2022 00:50:57 +0200 Subject: [PATCH 2/2] Update events.md fix: Oops, the event object in $emit needs its event prototype of course, so no spreading notation is possible. --- src/v2/guide/events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v2/guide/events.md b/src/v2/guide/events.md index 9c5df2c6ef..091dc3a5ec 100644 --- a/src/v2/guide/events.md +++ b/src/v2/guide/events.md @@ -181,7 +181,7 @@ To address this problem, Vue provides **event modifiers** for `v-on`. Recall tha Please note that with the exception of `.once` the modifiers above only work with **native events**.

-When emitting native-looking events from components, such as 'click', it is a good practice to also emit the native event. eg. `this.$emit('click', {...data, ...event})`. If you haven't read about components yet, don't worry about this for now. +When emitting native-looking events from components, such as 'click', it is a good practice to also emit the native event. eg. `event.data = {...}; this.$emit('click', event)`. If you haven't read about components yet, don't worry about this for now.