forked from nuxt/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(api): add
defineNuxtComponent
utils (nuxt#7618)
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Damian Głowala <48835293+DamianGlowala@users.noreply.github.com> Co-authored-by: Pooya Parsa <pooya@pi0.io>
- Loading branch information
1 parent
347abcd
commit f82a4b6
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
# `defineNuxtComponent` | ||
|
||
::NeedContribution | ||
`defineNuxtComponent()` is a helper function for defining type safe Vue components using options API similar to [defineComponent()](https://vuejs.org/api/general.html#definecomponent). `defineNuxtComponent()` wrapper also adds support for `asyncData` component option. | ||
|
||
::alert{type=warning} | ||
Options API support for `asyncData` may well change before the stable release of Nuxt 3. | ||
:: | ||
|
||
::Alert | ||
Using `<script setup lang="ts">` is the recommended way of declaring Vue components in Nuxt 3. | ||
:: | ||
|
||
:ReadMore{link=/getting-started/data-fetching#options-api-support} | ||
|
||
## `asyncData()` | ||
|
||
If you choose not to use `setup()` in your app, you can use the `asyncData()` method within your component definition: | ||
|
||
```vue [pages/index.vue] | ||
<script lang="ts"> | ||
export default defineNuxtComponent({ | ||
async asyncData() { | ||
return { | ||
data: { | ||
greetings: 'hello world!' | ||
} | ||
} | ||
}, | ||
}) | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { splitByCase, upperFirst } from 'scule' | ||
|
||
export default (title, link) => { | ||
return title || (link.startsWith('http') && link) || link.split('/').filter(Boolean).map(part => splitByCase(part).map(p => upperFirst(p)).join(' ')).join(' > ').replace('Api', 'API') | ||
return title || (link.startsWith('http') && link) || link.split(/[/#]/).filter(Boolean).map(part => splitByCase(part).map(p => upperFirst(p)).join(' ')).join(' > ').replace('Api', 'API') | ||
} |