Skip to content

prop "default" value based on other prop #106

@mesqueeb

Description

@mesqueeb

Currently we can set default values like so:

export default {
  name: 'Knight',
  props: {
    name: {
      type: String,
    },
    isKnight: {
      type: Boolean,
      default: false,
    },
  },
}

In this example we'd have to pass if a person is a knight or not:

<Knight name="John" is-knight="false" />

However, very often I need to look at other props and calculate a props' default state based on these other props.

A nice addition to default values for props could be:

export default {
  name: 'Knight',
  props: {
    name: {
      type: String,
    },
    isKnight: {
      type: Boolean,
      default: props => props.name.includes('Sir'),
    },
  },
}

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