Nuxt 不会自动从嵌套目录导入组件 [英] Nuxt not automatically importing components from nested directory

查看:37
本文介绍了Nuxt 不会自动从嵌套目录导入组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 nuxt 应用程序中,嵌套目录中的组件没有按预期自动导入.对于我的一些组件,我有如下内容:

In my nuxt app, components in nested directories are not automatically importing as expected. For some of my components i have something like the following:

vue 2.6.12, nuxt 2.15.0

components\ 目录结构

TopArea\
--SomeComponent.vue

<template>
  <header class="header">
    <div>Hello</div>
    <SomeComponent />
  </header>
</template>

应用程序中没有其他组件具有名称 SomeComponent.在上面的示例中,我收到错误消息:Unknown custom element: - 您是否正确注册了组件?对于递归组件,请确保提供名称";选项..我可以通过在组件文件名 (TopAreaSomeComponent) 之前指定目录名称、使用 nuxt.config 中的前缀选项或手动导入组件来解决此问题.这令人困惑,因为 docs 状态:

No other component in the application has the name SomeComponent. In the example above i get the error: Unknown custom element: <SomeComponent> - did you register the component correctly? For recursive components, make sure to provide the "name" option.. I can get around the issue by specifying the directory name before the component filename (TopAreaSomeComponent), use the prefix option in nuxt.config, or by manually importing the component. This is confusing because the docs state:

嵌套目录
如果您在嵌套目录中有组件,例如:
components/baseButton.vue
组件名称将基于其自己的文件名.因此,该组件将是:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆