当前位置: 首页 > news >正文

重庆江津网站建设thinkphp5 做网站

重庆江津网站建设,thinkphp5 做网站,成都到西安多少公里路,上海制作网页哪家好原文链接#xff1a;https://blazor-university.com/routing/navigating-our-app-via-code/通过代码导航源代码[1]从 Blazor 访问浏览器导航是通过 NavigationManager 服务提供的。这可以使用 razor 文件中的 inject 或 CS 文件中的 [Inject] 属性注入到 Blazor 组件中。Navig… 原文链接https://blazor-university.com/routing/navigating-our-app-via-code/通过代码导航源代码[1]从 Blazor 访问浏览器导航是通过 NavigationManager 服务提供的。这可以使用 razor 文件中的 inject 或 CS 文件中的 [Inject] 属性注入到 Blazor 组件中。NavigationManager 服务有两个特别的成员NavigateTo 和 LocationChanged。LocationChanged 事件将在检测导航事件[2]中更详细地解释。NavigateTo 方法NavigationManager.NavigateTo 方法使 C# 代码能够控制浏览器的 URL。与截获的导航一样浏览器实际上并不导航到新的 URL。相反浏览器中的 URL 被替换之前的 URL 被插入到浏览器的导航历史中但没有向服务器请求新页面的内容。通过 NavigateTo 进行的导航将触发 LocationChanged 事件传递新 URL 并为 IsNavigationIntercepted 传递 false。对于此示例我们将再次更改标准 Blazor 模板。我们将使用我们之前在路由参数[3]和可选路由参数[4]中学到的知识。首先删除 Index.razor 和 FetchData.razor 页面并删除 NavMenu.razor 文件中指向这些页面的链接。同样在 NavMenu 中将 counter 链接的 href 更改为 为 href因为我们将使其成为默认页面。编辑 Counter.razor 并给它两个路由“/” 和 “/counter/{CurrentCount:int}”同时确保它来自 CounterBase 类这样我们就可以在浏览器的控制台窗口中看到导航日志 - CounterBase.cs 文件之前在 OnLocationChanged 部分中进行了概述。page / page /counter/{CurrentCount:int} inherits CounterBase我们还需要更改 currentCount 字段使其成为具有 getter 和 setter 的属性并将其装饰为 [Parameter]。请注意它也已从 camelCase 重命名为 PascalCase。[Parameter] public int CurrentCount { get; set; }我们现在有一个 counter 页面可以简单地访问应用程序的主页也可以通过指定 /counter/X 来访问其中 X 是一个整数值。NavigationManager 被注入到我们的 CounterBase 类中因此可以在 Counter.razor 文件中访问。code {[Parameter]public int CurrentCount { get; set; }bool forceLoad;void AlterBy(int adjustment){int newCount  CurrentCount  adjustment;UriHelper.NavigateTo(/counter/  newCount, forceLoad);} }我们将从两个按钮调用 AlterBy 方法一个用于增加 CurrentCount一个用于减少它。还有一个用户可以选择的选项 forceLoad它将在调用 NavigateTo 时设置相关参数以便我们看到差异。整个文件最终应如下所示page / page /counter/{CurrentCount:int} implements IDisposable inject NavigationManager NavigationManagerh1Counter value  CurrentCount/h1div classform-checkinput bindforceLoad typecheckbox classform-check-input idForceLoadCheckbox /label classform-check-label forForceLoadCheckboxForce page reload on navigate/label /divdiv classbtn-group rolegroupbutton onclick( ()  AlterBy(-1) ) classbtn btn-primary-/buttoninput valueCurrentCount readonly classform-control /button onclick( ()  AlterBy(1) ) classbtn btn-primary/button /div a classbtn btn-secondary href/Counter/0Reset/a pemPage redirects to ibm.com when count hits 10!/em /pcode {[Parameter]public int CurrentCount { get; set; }bool forceLoad;void AlterBy(int adjustment){int newCount  CurrentCount  adjustment;if (newCount  10)NavigationManager.NavigateTo(https://ibm.com);NavigationManager.NavigateTo(/counter/  newCount, forceLoad);}protected override void OnInitialized(){// Subscribe to the eventNavigationManager.LocationChanged  LocationChanged;base.OnInitialized();}private void LocationChanged(object sender, LocationChangedEventArgs e){string navigationMethod  e.IsNavigationIntercepted ? HTML : code;System.Diagnostics.Debug.WriteLine($Notified of navigation via {navigationMethod} to {e.Location});}void IDisposable.Dispose(){// Unsubscribe from the event when our component is disposedNavigationManager.LocationChanged - LocationChanged;} }单击 - 或 按钮将调用 AlterBy 方法该方法将指示 NavigationManager 服务导航到 /counter/X其中 X 是调整后的 CurrentCount 的值——在浏览器的控制台中产生以下输出WASM通过代码通知导航到 http://localhost:6812/counter/1 WASM通过代码通知导航到 http://localhost:6812/counter/2 WASM通过代码通知导航到 http://localhost:6812/counter/3 WASM通过代码通知导航到 http://localhost:6812/counter/4单击重置链接将导航到 /counter/0重置 CurrentCount 的值。WASM通过代码通知导航到 http://localhost:6812/counter/1 WASM通过代码通知导航到 http://localhost:6812/counter/2 WASM通过代码通知导航到 http://localhost:6812/counter/3 WASM通过代码通知导航到 http://localhost:6812/counter/4 WASM通过 HTML 通知导航到 http://localhost:6812/Counter/0ForceLoadforceLoad 参数指示 Blazor 绕过其自己的路由系统而是让浏览器实际导航到新 URL。这将导致对服务器的 HTTP 请求以检索要显示的内容。请注意导航到站外 URL 不需要强制加载。调用 NavigateTo 到另一个域将调用完整的浏览器导航。使用本节的 GitHub 示例。在浏览器的控制台窗口中查看 IsNavigationIntercepted 在通过按钮和重置链接导航时有何不同并在浏览器的网络窗口中查看根据您是否将 forceLoad 设置为 false 进行导航。将 forceLoad 设置为 true 进行导航。导航到站外 URL。要观察最后一种情况您可能希望更新 AdjustBy 方法以在 CurrentValue 传递特定值时进行站外导航。void AlterBy(int adjustment) {int newCount  CurrentCount  adjustment;if (newCount  10)NavigationManager.NavigateTo(https://ibm.com);NavigationManager.NavigateTo(/counter/  newCount, forceLoad); }参考资料[1]源代码: https://github.com/mrpmorris/blazor-university/tree/master/src/Routing/NavigatingViaCode
http://www.zqtcl.cn/news/579171/

相关文章:

  • 企业网站开发教程网站建设更改
  • 违法网站怎么做安全wordpress自定义应用
  • 四平英文网站建设wordpress添加特效
  • 如何在手机上制作网站企业网站 微博模块
  • 网站内容规范网站建设建设公司哪家好
  • 深圳网站制作公司地址如何制作手机版网站
  • 深圳定制网站制作报价网络交易平台
  • 鞍山网站制作报价wordpress手机客户端端
  • 开发触屏版网站标签苏州沧浪区做网站的
  • 网站接入商钓鱼网站链接怎么做
  • 建设部机关服务中心网站网站建设维护费 会计科目
  • 网站解析后怎么解决方法淘宝网站建设方案模板
  • 淘宝客可以自己做网站推广吗营销网络建设怎么写
  • 上海高端网站制作广告设计培训课程
  • 互联网站平台有哪些建筑工程教育网官网
  • 广告传媒公司哪家好职场seo是什么意思
  • 番禺龙美村做网站博山区住房和城乡建设局网站
  • 山东网站建设xywlcnwordpress如何创建导航
  • 直接用ip访问网站网站开发常用字体
  • 江西省城乡建设培训网 官方网站杭州十大软件公司
  • 建设网站需要什么设备南昌购物网站制作
  • 做家具的网站工作单位怎么填
  • 福州建设银行官网招聘网站山西建设公司网站
  • 集团网站建设方案中卫网站推广制作
  • 射阳网站建设电商运营团队结构图
  • 有没有女的做任务的网站计算机网站开发专业
  • 怎么样开始做网站网站建设 营业执照 经营范围
  • 威海做网站网站建设方案书 模版
  • 泗阳做网站南昌建设
  • 做企业网站用什么软件深圳制作企业网站