Skip to content

docs: clarify .once listener attachment semantics#3425

Open
happysnaker wants to merge 1 commit into
vuejs:mainfrom
happysnaker:docs-once-listener-attachment
Open

docs: clarify .once listener attachment semantics#3425
happysnaker wants to merge 1 commit into
vuejs:mainfrom
happysnaker:docs-once-listener-attachment

Conversation

@happysnaker

Copy link
Copy Markdown

Summary

  • clarify that .once applies once per listener attachment
  • explain that the listener is removed after the first invocation
  • note that recreating the element or child component attaches a fresh listener

Closes #3033

Note

This PR supersedes #3423, which I had to close after the original fork relationship was broken during repo visibility changes on my side. The content is being resubmitted unchanged from a proper public fork.

@netlify

netlify Bot commented Jun 30, 2026

Copy link
Copy Markdown

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit cacf415
🔍 Latest deploy log https://app.netlify.com/projects/vuejs/deploys/6a4383de0c743d00080daa83
😎 Deploy Preview https://deploy-preview-3425--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

- `.self` - only trigger handler if event was dispatched from this element.
- `.{keyAlias}` - only trigger handler on certain keys.
- `.once` - trigger handler at most once.
- `.once` - trigger handler at most once for each listener attachment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"listener attachment" is not very clear to me. What about:

Suggested change
- `.once` - trigger handler at most once for each listener attachment.
- `.once` - trigger handler at most once for each event listener.


`v-on` also supports binding to an object of event / listener pairs without an argument. Note when using the object syntax, it does not support any modifiers.

The `.once` modifier removes the listener after its first invocation. If the element or child component is re-created later, a new listener is attached, so it can run once again.

@bencodezen bencodezen Jul 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is slightly inaccurate given .once has different behavior for native DOM elements vs components.

Rather than a dedicated paragraph here though, maybe it makes more sense for it to be described more in depth in the list?

See https://github.com/vuejs/docs/pull/3425/changes#r3521256033

- `.self` - only trigger handler if event was dispatched from this element.
- `.{keyAlias}` - only trigger handler on certain keys.
- `.once` - trigger handler at most once.
- `.once` - trigger handler at most once for each listener attachment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `.once` - trigger handler at most once for each listener attachment.
- `.once` - trigger handler at most once for each event listener. The event is removed in native DOM events and ignored (rather than removed) in a component emitted event instance.

@bencodezen bencodezen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @happysnaker! I left some comments on the PR. Let me know what you think or if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v-on modifier .once triggers handler at most once... per what?

2 participants