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

22 lines
428 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 {
beforeCreate () {
2017-07-10 11:52:10 +00:00
this.component = () => getPost(this.$route.params.slug)
}
}
</script>
2022-09-03 12:46:48 +00:00
<style src="@/assets/css/post.css" />