Search code examples
javascriptvue.jssettingsvuetify.jsdefault

Vuetify set outlined for all v-text-field by default


Is there are simple way to change default value of props "outlined" for all "v-text-field" across entered project?

https://vuetifyjs.com/en/components/text-fields

enter image description here


Solution

  • You could create a wrapper component and extends from VTextField (see treeshaking) and customise the default value(s).

    import Vue from 'vue';
    import { VTextField } from 'vuetify/lib';
    
    Vue.component('TextFieldOutlined', {
      extends: VTextField,
      props: {
        outlined: {
          type: Boolean,
          default: true
        }
      }
    })
    

    Using it like:

    <text-field-outlined
      label="Some label"
      clearable
      dense>
    </text-field-outlined>
    

    FWIW, extending a component means all base component's props are passed along and thus equally usable.