gpt4 book ai didi

javascript - 有没有办法在 Blazor 中隐藏一个 div?

转载 作者:行者123 更新时间:2023-12-02 02:08:44 25 4
gpt4 key购买 nike

我正在使用 Blazor,我想在按下 navbar-toggler-icon 时隐藏边栏。列表项折叠,但问题是 div 仍然存在。

    <div class="page">
<div class="sidebar">
<div class="nav-top-row pl-4 navbar navbar-dark">
<button class="navbar-toggler" @onclick="CheckCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="">NavBar</a>
</div>

<div class="@NavMenuCssClass">
<ul class="nav flex-column">
<li class="nav-item px-0">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-0">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</li>
<li class="nav-item px-0">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
</ul>
</div>
</div>

<div class="main">
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/" target="_blank">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
</div>

@code {
private bool collapseNavMenu = false;

public string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void CheckCollapse()
{
collapseNavMenu = !collapseNavMenu;
}
}

最佳答案

这比您想象的要容易。

@if(!collapseNavMenu)
{
<div class="sidebar">
... as before
</div>
}

关于javascript - 有没有办法在 Blazor 中隐藏一个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68020569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com