mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Update component injection example
This commit is contained in:
parent
2cc78c0446
commit
3e36219a43
@ -1,16 +1,19 @@
|
||||
<template>
|
||||
<BlogArticle/>
|
||||
<component :is="comp"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const components = {}
|
||||
const files = require.context('@/articles', false, /\.vue$/)
|
||||
files.keys().forEach((filename) => {
|
||||
const name = filename.replace('./', '').replace('.vue', '')
|
||||
components[name] = () => import('@/articles/' + name + '.vue').then((m) => m.default || m)
|
||||
})
|
||||
|
||||
export default {
|
||||
async asyncData({ params, error }) {
|
||||
const slug = params.slug || 'hello'
|
||||
try {
|
||||
this.components.BlogArticle = await import(`~/articles/${slug}.vue`)
|
||||
} catch (e) {
|
||||
error({ statusCode: 404, message: 'Article not found' })
|
||||
}
|
||||
}
|
||||
return { comp: params.slug }
|
||||
},
|
||||
components
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user