Question3r
Question3r

Reputation: 3802

create component presets from base components

I would like to know if I can preset some props of components. I'm using Vuetify for this sample: Let's say you would want to customize the v-btn with some props. So the customized implementation would act as a child component because it still offers everything the parent component does but it implements some props directly.

You want to have some predefined buttons with a specific color so you could create your child button like

<template>
    <v-btn color="primary"></v-btn>
</template>

but this would be bad because you still want to offer all the props and listeners the "real" button does. You just want to implement some props.

Is there a simple way I can achieve that?

Upvotes: 0

Views: 71

Answers (1)

ellisdod
ellisdod

Reputation: 1734

You can import the VBtn component as a mixin and redefine the prop defaults.

import {VBtn} from 'vuetify/lib'
export default {
  name : 'VBtnGreen',
  mixins: [VBtn],
  props: {
   color : {
     default : 'green'
   }
  }
}

Upvotes: 4

Related Questions