Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend a component in Vue 3?

The import is working just fine in case I try to use the component from element-plus directly.

What I'm trying to do though, is to extend a component from element-plus library (it uses the composition api from Vue 3) and add some additional properties to my component and methods.

In Vue 2 it would look something like this:

export default {
  extends: SomeComponent
}

In Vue 3 this seems to not be working anymore.

I've read about defineComponent but so far, without success implementing it.

Can someone shed me some lights? Thanks.

like image 284
pmpc Avatar asked Sep 08 '25 07:09

pmpc


1 Answers

In order to extend a component that uses Composition API whereas another still uses Options API, we need to also do the setup, such as:

export default { extends: SomeComponent, setup: SomeComponent.setup }

like image 63
pmpc Avatar answered Sep 10 '25 00:09

pmpc