Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

docs(api): add defineNuxtComponent utils #7618

Merged
merged 9 commits into from
Sep 20, 2022
24 changes: 22 additions & 2 deletions docs/content/3.api/3.utils/define-nuxt-component.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# `defineNuxtComponent`

::NeedContribution
::
`defineNuxtComponent()` is a helper function for defining type safe Vue components within a Nuxt application. `defineNuxtComponent()` is a wrapper around [defineComponent()](https://vuejs.org/api/general.html#definecomponent) function that supports inferring the props passed toΒ `setup()` function when we use Composition API withoutΒ `<script setup>`.

`defineNuxtComponent()` also takes care of resolving the promise returned by `useAsyncData()` in Vue components found at `components/` and `pages/` directory or in the `~/app.vue` component found at the root of your Nuxt application.

Any Vue 3 components written in Nuxt application without `<script setup lang=β€œts”>` can use `defineNuxtComponent()` helper function to leverage the benefits of TypeScript.

## Example

```vue [pages/index.vue]
<script lang="ts">
import { defineComponent } from 'vue'
export default defineNuxtComponent({
async setup(props) {
const { data } = await useAsyncData('count', () => Promise.resolve({data: { name: 'Hello world!'}}))

return {
data
}
}
})
</script>
```