Update component injection example

This commit is contained in:
Sébastien Chopin 2017-07-10 08:56:02 +02:00
parent 2cc78c0446
commit 3e36219a43

View File

@ -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>