如何动态导入Vue 3组件?

11
根据这篇文章,我想将组件动态导入到我的Vue 3应用程序中。视图的代码如下:
<template>
  <div class="page">
      <latest-box v-if="showLatestBox" />
  </div>
</template>


<script>
// @ is an alias to /src
// This works well. 
//import LatestBox from '@/components/LatestBox.vue'


export default {
    name: 'Page 1',

    data() {
        return {
            showLatestBox: true,
        }
    },

    components: {
        LatestBox: () => import('@/components/LatestBox.vue')  // This does not work
    }
}
</script>

代码没有报错但是页面上没有看到组件。如果我使用第一个导入样式,它可以工作。我漏掉了什么吗?

1个回答

32

2
由于链接现在重定向到vuejs前页,这里是相关指南的链接:https://vuejs.org/guide/components/async.html - Dodge
我需要这个项目,因为它支持许多不同类型的复杂编辑器,所以我只想加载实际需要的那一个。我爱你。 - Oddman
太棒了!谢谢你。运作得很顺利。 - jacob_frankovic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接