Skip to content

Thoughts on property defaults. #1834

@amanpatel

Description

@amanpatel

Consider a component caled Box with the following property:

export default { props: { type: { type: String, default: "text" } } }

The intension of the component designer here is that anything we don't have a meaningful input for "type", it should be "text".

In Vue it seems that defaults are assigned only if the property is omitted. Consider the following example of using the box component.

<template> Box type: <box :type="box_type" /> Box text type: <box /> </template>

In the first case if "box_type" is defined, this works well and good. If "box_type" is undefined for whatever reason, this causes the Box component's type property to be unset and a warning to be issued in the console.

The second usage of works as expected and the property defaults to "text".

Should undefined property values cause defaults to be assigned? I think it would make for a nicer development practice.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions