我已经阅读了有关此主题的几篇文章,但经过数小时仍找不到解决方案。
我无法弹出 NavMenu.razor 中的子菜单。
我尝试的每个解决方案都不起作用。
我什至直接从 Bootstrap4 复制了示例,如下面的代码所示,但它不起作用。
除此之外,菜单完美无缺。
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-primary fixed-top">
<div class="d-none d-sm-block" style="padding:0 20px 0 0;">
<img src="/Client/Images/CompanyLogo.jpg" alt="Company logo" style="width:100%; height:40px; padding:0 0 0 5px; margin:0" ; />
</div>
<button class="navbar-toggler" @onclick="ToggleNavMenu" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="@NavMenuCssClass navbar-collapse d-sm-inline-flex flex-sm-row-reverse" @onclick="CollapseNavMenu">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-light" href="" Match="NavLinkMatch.All">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" href="\PurchaseOrders\OrderMain">Orders</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
@code {
bool collapseNavMenu = true;
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
void CollapseNavMenu()
{
collapseNavMenu = true;
}
}