在我的 nuxt 应用程序中,嵌套目录中的组件不会按预期自动导入。对于我的一些组件,我有如下内容:
vue 2.6.12, nuxt 2.15.0
components\ 目录结构
TopArea\
--SomeComponent.vue
Run Code Online (Sandbox Code Playgroud)
<template>
<header class="header">
<div>Hello</div>
<SomeComponent />
</header>
</template>
Run Code Online (Sandbox Code Playgroud)
应用程序中没有其他组件具有名称SomeComponent。在上面的示例中,我收到错误:Unknown custom element: <SomeComponent> - did you register the component correctly? For recursive components, make sure to provide the "name" option.. 我可以通过在组件文件名 ( TopAreaSomeComponent)之前指定目录名、使用 nuxt.config 中的前缀选项或手动导入组件来解决这个问题。这令人困惑,因为文档说明:
嵌套目录
如果您在嵌套目录中有组件,例如:
components/baseButton.vue
组件名称将基于其自己的文件名。因此,该组件将是:
<button />
它继续说“为了清楚起见,我们建议您在文件名中使用目录名称”。但这似乎是规则而不是建议。如果我不使用目录名作为文件名的一部分,则动态导入不适用于嵌套目录中的组件。
这是文档中的错误还是我读错了?
nuxt.js ×1