Learn how to implement dynamic component import in Vue 3
<p>According to this article, I want to dynamically import components into my Vue 3 application. The code for the view is as follows: </p>
<pre class="brush:php;toolbar:false;"><template>
<div class="page">
<latest-box v-if="showLatestBox" />
</div>
</template>
<script>
// @ is an alias for /src
// This method works
//import LatestBox from '@/components/LatestBox.vue'
export default {
name: 'Page 1',
data() {
return {
showLatestBox: true,
}
},
components: {
LatestBox: () => import('@/components/LatestBox.vue') // This method is invalid
}
}
</script></pre>
<p>The code does not report an error, but I cannot see the component on the page. If I use the first way of importing, it works. Did I miss something? </p>