繁体   English   中英

Blazor 无法从其他文件夹中找到引用的组件

[英]Blazor can't find referenced component from other folder

我正在尝试 Blazor WebAssembly,并希望在 Visual Studio 预生成的示例项目之上创建一些新组件。

所以,基本上我最终得到的是以下文件夹结构:

Project
\ Components
  \ Navigation
    \ BurgerMenu.razor
      BurgerMenu.razor.css
      BurgerMenu.razor.less
\ Shared
  \ MainLayout.razor
    MainLayout.razor.css
    MainLayout.razor.less

到目前为止,一切都很好。 这是我的组件:

MainLayout.razor:

@using Components.Navigation;

@inherits LayoutComponentBase

<div class="sidebar">
    <BurgerMenu />
</div>

<div class="LayoutContainer">
    @Body
</div>

汉堡菜单.razor:

<div>
    Test Component
</div>

@code
{
}

正如你所看到的,到目前为止,真的没有什么可写的。

但是,我无法让它正常工作。 每个版本都会抱怨warning RZ10012: Found markup element with unexpected name 'BurgerMenu'. If this is intended to be a component, add a @using directive for its namespace. warning RZ10012: Found markup element with unexpected name 'BurgerMenu'. If this is intended to be a component, add a @using directive for its namespace.

所以,我现在有点迷路了。 根据官方文档,@using 语句应该是从文件夹导入组件的正确方法 - 就在那里。 但是,这仍然行不通。

如果我在 /Shared 文件夹中移动 BurgerMenu.razor,一切正常。

那么,我做错了什么?

我原以为 using 语句需要包含您的项目名称:

@using Project.Components.Navigation;

如果我尝试与您类似的事情,编辑器会用红色强调 using 语句(不带项目名称)。

为我重新启动 Visual Studio 后,此问题已解决。 我正在运行 Professional 2019,显然智能感知卡住了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM