question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] extend Vuetify components

See original GitHub issue

What problem does this feature solve?

Right now, AFAIK, there is easy way to extend Vuetify component. I am writing a library and I want one of my library components to extend for example VInput component. Vuetify does not export it’s components - it only exports plugin function that install those components at “runtime”. What I need is something like this:

<script>
  import { Vinput } from 'vuetify/components'

  export default {
    extends: VInput
  }
</script>

I know that components can be imported via import VInput from 'vuetify/src/components/VInput/VInput' for example, but then to build such app I would need all loaders that vuetify uses to build/transpile its code (typescript / stylus / etc)…

What is your proposed solution?

Something like this:

<script>
  import { Vinput } from 'vuetify/components' // <--------------- export all components

  export default {
    extends: VInput
  }
</script>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
AdmiralPotatocommented, May 23, 2019

Unfortunately @nekosaur’s approach of importing a component from the vuetify/es5/components/* path fails for me as well, because even the es5 components still somehow require the stylus loader? (same issue as @alekbarszczewski @slushnys @pynner)

I have created a solution that works in the case where you’re trying to import a specific component to be able to extend it, but it will not work of you’re trying to import specific components with the intent of tree shaking.

It’s a bit hacky, but it gets the job done using the same pre-built/dist copy of the Vuetufy components that are installed globally via Vue.use(Vuetify). Fortunately, using this approach also means that you can define your components that extend the Vuetify components even before Vuetify is installed globally. This approach could even be adapted to work in the (live browser/Vuetify via cdn) environment if you use window.Vuetify instead of the imported version here.

Let’s start by breaking all of the components free, so we never have to implement this hack in any more that one place.

VuetifyActuallyAlacarte.js aka “Hippity Hoppity I’m Coming For That Property”

import Vuetify from 'vuetify'

let output
// Subvert the Vuetify.install method to give us the same built components that
// it normally provides to the Vue.use method when registering Vuetify globally.
const syntheticSubvertingVue = {
  use (installer, options) {
    output = {
      ...options
    }
  }
}
Vuetify.install(syntheticSubvertingVue)

// At the time of writing this at Vuetify 1.5.14, this output object gives us
// properties `components` and `directives`, in case you need either of those
export default output
export const components = output.components
export const directives = output.directives

In your cases, you’ll probably write something like this: CustomVInput.js

import { components } from './VuetifyActaullyAlacarte'
const VInput = components.VInput

export default {
  extends: VInput,
  ...
}

In my case, I wanted to extend the VTextField, which has a deprecation warning wrapper obscuring the actual component that I want to extend, so I need to unwrap it to get the real component - thankfully still accessible.

CustomVTextField.js

import { components } from '@shared/components/VuetifyActaullyAlacarte.js'
const VTextField = components.VTextField.$_wrapperFor

export default {
  extends: VTextField,
  ...
}

Hopefully this helps someone else out there!

6reactions
alekbarszczewskicommented, Sep 18, 2018

I tried it, but it complains that I need stylus loader. Would be best if it was possible to import components without modifying build step / configuration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently asked questions — Vuetify
How do I extend Vuetify components? Vuetify components are easily extendable by importing it and using the extends option in vue. Codepen ...
Read more >
Extend vuetify VTextField - Stack Overflow
Notice this extends from the base component ( VTextField ) and sort of "overrides" the original render function, returning customized ...
Read more >
Building Packageable Components to Extend Vuetify with ...
In this installment, we're going to build out the custom component we began in the last post, a Vuetify extension called VAddressFields, ...
Read more >
Vuetify extending components - CodeSandbox
Vuetify extending components ... Manage Extension. Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >
Create wrapper components for Vuetify components
That's all there is to it! You can now use the "component wrapper" technique to extend Vuetify components and also to build apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found