【问题标题】:Async load components locally and alias the name本地异步加载组件并为其命名
【发布时间】:2021-06-24 16:14:09
【问题描述】:

我正在迁移到 vue.js 3,但没有找到解决方案来使其正常工作:

在 Vue.js 2 中,我能够像这样加载组件并分配别名:

components: {
        checkbox: () => import('./CheckboxField'),
}

在 Vue.js 3 中,我必须使用 new way 来导入组件。

这就是我现在所做的:

components: {
        AsyncComponent: defineAsyncComponent(() =>
            import('./CheckboxField.vue')
        )
    },

但我不明白如何像以前那样给这个CheckboxField 起一个别名。

【问题讨论】:

  • 别名是什么意思?

标签: vue.js vue-component vuejs3


【解决方案1】:

在您的示例中,AsyncComponent 组件名称,不是吗?所以:

components: {
    checkbox: defineAsyncComponent(() =>
        import('./CheckboxField.vue')
    )
}

【讨论】:

  • 哦,哇。 :-D 是的,你完全正确。我的 IDE 显示,那个“复选框”没有被导入,所以我猜我错了 - 但确实我的 IDE 错了 ;-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
  • 2013-06-12
相关资源
最近更新 更多