From e5ea7c21fa866d434dd82ba9494c1af205708ccd Mon Sep 17 00:00:00 2001 From: Leo <3853621+leoelz@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:05:08 -0300 Subject: [PATCH 1/3] Events as Props: more details added I wrote different cases [In the Playground](https://play.vuejs.org/#eNqdVcFu2zAM/RXCGOYUTewBvaVu0HUIsO6wFmuHHeYdHIdJ3NqSIclJiyDfsPtO+4x9z35gvzBKslynddJ1PRQx+UQ98pHi2ntblsGyQm/oRTIVWalAoqrKUcyyouRCwRoEzmADM8EL8AnqHze+d7woa0cQ6g8dyo9ZzFLOpIJZJnAKJzpC780BnbPmUvBSXrArXuB4iUxd35dYo3xfw2I2q1iqMs4ANeB9wqY5ip756Nvz+tDBOmZgIYFKxBxVINV9jkHKcy4opD8XiEwzBjg8NHSCZZJXaCxdPKybjjaXEHQTsyi05aHC0IfCoswThfQFULODNMlzSjeajNbrOvXNJgonI1BZgTKaCAM32fIZvDI3BPzh/mF9trM+NpQOEC2ORozDor7294+ff359j0KyGq8RJbS/sRidz6AFziRMcZYxnPYhUToNlbE5KA6VRIhSPsXRU2K9gyg0LkgkJCRKkdFZAassz0k2WeUKMgYJaH15joBCcBFEId3vGJ9KF82ReUT5AXASe23ZY8+l48IMjHtfHIvYF2jYym9HpDbkmVCDp7S6hdnG7oxKhfuyQAZlIqUWSBd9Kzh1itbC9IrpMbJr4y1OkskgTSQaK+lNwpLYaoHN2RVnvoIJkmakYilQUauu9HWVuUxjKVTdDVrsWn4TshZ/p7qvt+rmLpU7y7GnxP/QEjUH+rWjd13nUiUYV1Qx97QcQ6Z8086JEMk9NbNawITTP1cnh5RDN7sAAzjrhFAQdC9Aq5Q7yxi0Q35+hN09gFbqlwyhqZKVKgpb75bX95Qk6CybBzeSM9oA5jWNvZSEySi5C3obKFTsDcF4tI8S5KsPxqZEhX1nTxeY3nbYb+SdtsXeJTFEscTYa3z2xbbu8dVHvKPfjbPg0yon9B7nJ6Q0K83Rws6qujcanGF7bnYVFfhaju8UMumS0kQ1cmPwsUe7S/fkrtQf6B4FR+YcLQaqott7HSvUPrVjEkr24Cv4TTv78A30orOASy23AbQkd5DuTVi/Bs8vQC4SNjc7e/8Si6bZ0k3SpFKKLjxN8yy9pcmz5vqehsGrmoJZpfrPtHivnWW/BtHzQyusc+c152PPzkivdf7ANTm1veHUMHSz899cn47Yy6h2jGgn2Si0hd2evc1fgIY9Jg==) to understand the Events as Props --- src/guide/components/events.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/guide/components/events.md b/src/guide/components/events.md index 609aaa23cb..e72d0523a7 100644 --- a/src/guide/components/events.md +++ b/src/guide/components/events.md @@ -291,11 +291,16 @@ export default { ## Events as Props {#events-props} -You may also declare and pass `events` as `props`, by prefixing the capitalized event name with `on` -Using `props.onEvent` has a different behaviour than using `emit('event')`, as the former will pass only handle the property based listener (either `@event` or `:on-event`) +You may also declare and pass `events` as `props`, by prefixing the capitalized event name with `on`. + +Using `$props.onEvent` has a different behaviour than using `$emit('event')`, as `$props.onEvent` gets the callback function declared as a listener in the parent (either `@event` or `:onEvent`). :::warning -If both `:onEvent` and `@event` are passed `props.onEvent` might be an array of `functions` instead of `function`, this behavior is not stable and might change in the future. +If both `:onEvent` and `@event` are passed `$props.onEvent` might be an array of `functions` instead of `function`, this behavior is not stable and might change in the future. + +If no handler is defined, attempting to use `$props.onEvent()` as an emitter will result in a console error. + +When passing an event handler as a prop and kebab-case is used (ie: `:on-event`), the handler won't be interpreted when using the `$emit('event')` emitter. ::: -Because of this, it is recommended to use `emit('event')` instead of `props.onEvent` when emitting events. +Because of this, it is recommended to use `$emit('event')` instead of `$props.onEvent` when emitting events and declare event listener using event directives as `@event` instead of `:onEvent`. From 2b25d7be69a4759cdd464a7bd778e2d5502814ed Mon Sep 17 00:00:00 2001 From: Leo <3853621+leoelz@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:27:51 -0300 Subject: [PATCH 2/3] $ removal --- src/guide/components/events.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/guide/components/events.md b/src/guide/components/events.md index e72d0523a7..b188392d7d 100644 --- a/src/guide/components/events.md +++ b/src/guide/components/events.md @@ -293,14 +293,14 @@ export default { You may also declare and pass `events` as `props`, by prefixing the capitalized event name with `on`. -Using `$props.onEvent` has a different behaviour than using `$emit('event')`, as `$props.onEvent` gets the callback function declared as a listener in the parent (either `@event` or `:onEvent`). +Using `props.onEvent` has a different behaviour than using `emit('event')`, as `props.onEvent` gets the callback function declared as a listener in the parent (either `@event` or `:onEvent`). :::warning -If both `:onEvent` and `@event` are passed `$props.onEvent` might be an array of `functions` instead of `function`, this behavior is not stable and might change in the future. +If both `:onEvent` and `@event` are passed `props.onEvent` might be an array of `functions` instead of `function`, this behavior is not stable and might change in the future. -If no handler is defined, attempting to use `$props.onEvent()` as an emitter will result in a console error. +If no handler is defined, attempting to use `props.onEvent()` as an emitter will result in a console error. -When passing an event handler as a prop and kebab-case is used (ie: `:on-event`), the handler won't be interpreted when using the `$emit('event')` emitter. +When passing an event handler as a prop and kebab-case is used (ie: `:on-event`), the handler won't be interpreted when using the `emit('event')` emitter. ::: -Because of this, it is recommended to use `$emit('event')` instead of `$props.onEvent` when emitting events and declare event listener using event directives as `@event` instead of `:onEvent`. +Because of this, it is recommended to use `emit('event')` instead of `props.onEvent` when emitting events and declare event listener using event directives as `@event` instead of `:onEvent`. From 93dbc766b755f207f42ffcd6f85be6aaa6b69b40 Mon Sep 17 00:00:00 2001 From: Leo <3853621+leoelz@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:49:08 -0300 Subject: [PATCH 3/3] fix typos and replace event with someEvent --- src/guide/components/events.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/guide/components/events.md b/src/guide/components/events.md index b188392d7d..97d9fc87d2 100644 --- a/src/guide/components/events.md +++ b/src/guide/components/events.md @@ -293,14 +293,14 @@ export default { You may also declare and pass `events` as `props`, by prefixing the capitalized event name with `on`. -Using `props.onEvent` has a different behaviour than using `emit('event')`, as `props.onEvent` gets the callback function declared as a listener in the parent (either `@event` or `:onEvent`). +Using `props.onSomeEvent` has a different behaviour than using `emit('someEvent')`, as `props.onSomeEvent` gets the callback function declared as a listener in the parent (either `@someEvent` or `:onSomeEvent`). :::warning -If both `:onEvent` and `@event` are passed `props.onEvent` might be an array of `functions` instead of `function`, this behavior is not stable and might change in the future. +If both `:onSomeEvent` and `@someEvent` are passed, `props.onSomeEvent` might be an array of functions instead of a function, this behavior is not stable and might change in the future. -If no handler is defined, attempting to use `props.onEvent()` as an emitter will result in a console error. +If no handler is defined, attempting to use `props.onSomeEvent()` as an emitter, will result in a console error. -When passing an event handler as a prop and kebab-case is used (ie: `:on-event`), the handler won't be interpreted when using the `emit('event')` emitter. +When passing an event handler as a prop, and kebab-case is used (ie: `:on-some-event`), the handler won't be interpreted when using the `emit('someEvent')` emitter. ::: -Because of this, it is recommended to use `emit('event')` instead of `props.onEvent` when emitting events and declare event listener using event directives as `@event` instead of `:onEvent`. +Because of this, it is recommended to use `emit('someEvent')` instead of `props.onSomeEvent` when emitting events, and declare event listeners using the event directives as `@someEvent` instead of `:onSomeEvent`.