Function defineComponent()
A type helper for defining a Vue component with
type inference.
// options syntax
function defineComponent(
component: ComponentOptions
): ComponentConstructor
// function syntax (requires 3.3+)
function defineComponent(
setup: ComponentOptions['setup'],
extraOptions?: ComponentOptions
): () => any
const Foo = defineComponent(/* ... */)
type FooInstance = InstanceType<typeof Foo>
Function Signature
IdefineComponent()
also has an alternative
signature that is meant to be used with
Composition API and render functions or JSX.
This function works the same as the Composition API
setup()
function: it receives the props and the
setup context.
import { ref, h } from 'vue'
const Comp = defineComponent(
(props) => {
// use Composition API here like in <script setup>
const count = ref(0)
return () => {
// render function or JSX
return h('div', count.value)
}
},
// extra options, e.g. declare props and emits
{
props: {
/* ... */
}
}
)