How to use Nuxt Content with Composition API and TypeScript
See original GitHub issueHello, I would like to use Nuxt/Content into my project with the Nuxt-composition-api module and Typescript. I have test many methods to get a content from my directory.
Here is some examples :
setup() {
const {$content} = useContext()
const info = useAsync( () => {
$content('infos').fetch<InfoData>()
})
return {
info
}
}
const info = await $content('infos').fetch<InfoData>()
Here is my InfoData object :
interface InfoData {
age: number
hiring_status: string,
hiring_color: string
}
I have errors like "TypeError: Cannot read property 'value' of undefined"
or "TypeError: Cannot read property 'age' of undefined"
My infos.json file is :
{
"age": 18,
"hiring": {
"status": "available",
"color": "green"
}
}
Do you have an example to use the Nuxt content module with the composition api ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Getting Started with Nuxt + Composition API + TypeScript
Open your terminal and run this command npx create-nuxt-app nuxt-ts-composition-api make sure to select TypeScript, and $axios during the ...
Read more >Using TypeScript and Composition API with Nuxt and Netlify ...
1 (Optional) Install nuxt-vite · 2 Install nuxt-typescript and ESLINT packages · 3 Add the Composition API package · 4 Fetching Netlify CMS...
Read more >nuxt + nuxt-composition-api + typescript + @nuxt/content
Embed Embed this gist in your website. ; Share Copy sharable link for this gist. ; Clone via HTTPS Clone with Git or...
Read more >Nuxt-Comp-API-Content-Module-TypeScript - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >Scaffolding an app with Vue 3, Nuxt, and TypeScript
Also, for convenience, the Nuxt composition API module exports the @vue/composition-api methods and hooks, so you can import directly from @ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ArthurDanjou I’ve not tested this, but try:
@ArthurDanjou refs are unwrapped in the template (so there is no
.value
). You can find out more in the Vue 3 docs though note that there are some differences with Vue 2. You should make your conditionv-if="info && info.age"
.