mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
Update component injection example
This commit is contained in:
parent
2cc78c0446
commit
3e36219a43
@ -1,16 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<BlogArticle/>
|
<component :is="comp"/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 {
|
export default {
|
||||||
async asyncData({ params, error }) {
|
async asyncData({ params, error }) {
|
||||||
const slug = params.slug || 'hello'
|
return { comp: params.slug }
|
||||||
try {
|
},
|
||||||
this.components.BlogArticle = await import(`~/articles/${slug}.vue`)
|
components
|
||||||
} catch (e) {
|
|
||||||
error({ statusCode: 404, message: 'Article not found' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue
Block a user