Nuxt/examples/async-component-injection/pages/_slug.vue

22 lines
426 B
Vue
Raw Normal View History

2017-07-10 11:52:10 +00:00
<template>
<div class="post">
<Component :is="component" />
2017-07-10 11:52:10 +00:00
</div>
</template>
<script>
// See https://vuejs.org/v2/guide/components.html#Advanced-Async-Components
const getPost = slug => ({
2017-07-10 11:52:10 +00:00
component: import(`@/posts/${slug}`),
error: require('@/posts/404')
})
export default {
2017-10-31 13:43:55 +00:00
beforeCreate() {
2017-07-10 11:52:10 +00:00
this.component = () => getPost(this.$route.params.slug)
}
}
</script>
<style src="@/assets/css/post.css"/>