Skip to content

Event names using camelCase #308

Closed
Closed
@privatenumber

Description

@privatenumber

The Custom Events page sets a confusing and contradicting recommendation on event-name conventions.

At the top it recommends using kebab-case because HTML is case-insensitive:

Since event names will never be used as variable or property names in JavaScript, there is no reason to use camelCase or PascalCase. Additionally, v-on event listeners inside DOM templates will be automatically transformed to lowercase (due to HTML's case-insensitivity), so @myevent would become @myevent -- making myEvent impossible to listen to.

For these reasons, we recommend you always use kebab-case for event names.

However, a lot of code examples starting from the "Multiple v-model bindings" section contains camelCase event names:

$emit('update:firstName', $event.target.value) -> v-model:firstName="firstName"

This statement seems inaccurate too, considering part of the event name (eg. update:dataProperty) maps to a view-model property:

Since event names will never be used as variable or property names in JavaScript, there is no reason to use camelCase or PascalCase.

Edit:

  • Confirmed not working Codepen
  • Changing to kebab-case v-model.prop-name="..." where the emitted event can be either camelCase (update:propName) or kebab-case (update:prop-name) works. Codepen

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions