Skip to content

Warn against duplicate props/data fields #1166

Closed
@yyx990803

Description

@yyx990803

Problem

Currently the props are merged with the instance's own data, which has a few problems:

  1. Both data and props can declare the same property name. The order and priority of the merging is not clear. Should a prop overwrite the field with the same name in data? Or the other way around? Currently, the props' initial values are available inside data functions, but the same field returned in data gets overwritten by the prop.
  2. Once merged, it's not clear whether a component property is its "private" state or a prop that is passed down from (and thus can be changed by) the parent, unless you go and check the component's props declaration.

Proposal

Move props into its own name space, for example this.props. This avoids the merging problem (we can either make props a reserved field or make it $props) and makes it explicit that something is a prop that is obtained from outside the component.

Throw a warning if the user defines duplicate fields in data and props.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions