3

I have started using Vuetify, but I am looking for a way to modify the default props on some components.

Is there a way to do this?

i.e. Instead of constantly having to write:

<v-layout wrap></v-layout>

Can I make layouts default prop for wrap be true?

1 Answers1

3

something along these lines, but beware if you are new to vue.js you'll have to do some reading:

relevant doc: vue mixin, vue extends

js

// some already existing component, you need to get it somehow
// most likely via `import <something-to-import>`
let theExternalComponent = {
  props: { wrap: { default: false, type: Boolean } },
  template: "<li>wrap:{{wrap}}</li>"
};
// this simulates the global registration
Vue.component("v-some-external-component", theExternalComponent);

// -- lets start --

// lets extend that component - and overwrite the default prop for wrap
let extendedExternalwithOtherDefaults = {
  extends: theExternalComponent,
  mixins: [{ props: { wrap: { default: true } } }],
};

var app = new Vue({
  el: "#app",
  components: { "v-my-customized-component": extendedExternalwithOtherDefaults }
});

html (pug actually but that does not matter here)

div(id="app")
  ul
    v-some-external-component

    v-some-external-component(wrap)

    v-my-customized-component
    // now defaults to wrap:true

    v-my-customized-component(:wrap="false") 
    // you can still set the wrap to false if required

output

wrap:false
wrap:true
wrap:true
wrap:false

codepen: https://codepen.io/anon/pen/MLxbEW

tony19
  • 125,647
  • 18
  • 229
  • 307
birdspider
  • 3,034
  • 1
  • 16
  • 25
  • Thanks, this was exactly what I was looking for – Tristan Neumann Feb 20 '19 at 19:59
  • Do you have an example of how you used this @TristanNeumann? I'm struggling a bit to figure this out, as registering my new component appears to not do anything (throws unregistered component error). – Kendall Dec 16 '19 at 04:34