JavaScript停止使用AspNetCore Blazor



我面临以下困境。我正在用Blazor Server 3.1版本构建一个在AspNetCore中制作的应用程序,用于学习目的。当我添加AdminLTE模板时,应用程序作为一个整体工作,因为我可以激活侧菜单,使其显示或隐藏。从我添加一个调用AdminLTE模板的登录屏幕的那一刻起,所有菜单都停止工作。AdminLTE模板提供给用户的所有交互,显示和隐藏菜单,都停止工作。我该怎么做才能使菜单再次正常工作?JS为什么停止?

Arquivo:_Host.cshtml

<html lang="pt-br">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BlazorAdminLTE</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="~/AdminLTE/plugins/fontawesome-free/css/all.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- icheck bootstrap -->
<link rel="stylesheet" href="~/AdminLTE/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="~/AdminLTE/dist/css/adminlte.min.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition sidebar-mini">
<div class="content">
<app>
<component type="typeof(App)" render-mode="ServerPrerendered" />
</app>
</div>
<script src="_framework/blazor.server.js"></script>
<script src="~/AdminLTE/plugins/"></script>
<!-- jQuery -->
<script src="~/AdminLTE/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="~/AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="~/AdminLTE/plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="~/AdminLTE/dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="~/AdminLTE/dist/js/demo.js"></script>
<script type="text/javascript">
$(document).ready(function() {
bsCustomFileInput.init();
});
</script>
</body>
</html>

Arquivo:MenuVertical.razor

<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item has-treeview">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Dashboard
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="../../index.html" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Dashboard v1</p>
</a>
</li>
<li class="nav-item">
<a href="../../index2.html" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Dashboard v2</p>
</a>
</li>
<li class="nav-item">
<a href="../../index3.html" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Dashboard v3</p>
</a>
</li>
</ul>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->

Arquivo:LoginLayout.razor

@inherits LayoutComponentBase
<div class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<img src="images/logo_sise_transp-1.png" alt="Logo da empresa Sises" style="width: 263px;" />
</div>
<!-- /.login-logo -->
<div class="card">
<div class="card-body login-card-body" style="padding-top: 30px;padding-bottom: 30px;">
@Body
</div>
<!-- /.login-card-body -->
</div>
</div>
</div>

Arquivo:MainLayout.razor

@inherits LayoutComponentBase
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<MenuHorizontal />
</nav>
<!-- Menu Vertical -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<MenuVertical />
</aside>
<div class="main">
<div class="top-row px-4">
<AuthorizeView>
<Authorized>
<a href="/" @*@onclick="(() => Logout())">Logout*@</a>
</Authorized>
<NotAuthorized>
<a href="/">Login</a>
</NotAuthorized>
</AuthorizeView>
</div>
<div class="content-wrapper">
@Body
</div>
</div>

Arquivo:App.razor

<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<h1>404 Error</h1>
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>

我设法解决了JS问题。由于它是一个SPA应用程序,当我们想要访问Blazor中创建的页面时,它们不会更新,而且由于某种原因,在我的情况下,AdminLTE菜单被锁定,无法访问子菜单。在Blazor本身中,有一个在页面之间导航的命令,第一个参数是传递要访问的页面,第二个参数是是否应用刷新的可能性。默认情况下,此参数为false,但如果传递为true,则会更新页面。

结论:在代码的某个地方,您需要将第二个参数传递为true,以便更新屏幕。

NavigationManager.NavigateTo("/index",true(;

相关内容

  • 没有找到相关文章