<span id="pr50z"><big id="pr50z"><ins id="pr50z"></ins></big></span>
<span id="pr50z"></span>
  • <rp id="pr50z"></rp>
    1. <nobr id="pr50z"></nobr>
      \n\n<\/body>\n<\/html><\/pre>\n

      這里有一些事情需要注意。首先,我們添加了所有依賴項以便它們加載。其次,我們引用了一些尚不存在的新文件(app文件夾中的所有文件)。我們接下來將編寫這些文件。<\/p>\n

      讓我們進入我們的app文件夾并創(chuàng)建我們的app.js文件。這是一個非常簡單的文件。<\/p>

      root\n    app     (Angular應(yīng)用程序特定的JavaScript)\n    Content (CSS等)\n    Scripts (引用的JavaScript等)\n    ...\n    index.html<\/code><\/pre>\n

      此文件為我們做了幾件事。它設(shè)置了我們的主應(yīng)用程序模塊angularServiceDashboard,并注入了兩個外部引用——ng.epoch(這是我們的Epoch.js Angular指令)和n3-pie-chart(這是一個為Angular制作的、結(jié)構(gòu)良好的圖表庫)。<\/p>\n

      如果您注意到,我們還為backendServerUrl注入了一個值,它當然托管在其他地方,我們計劃在這里使用它。<\/p>\n

      讓我們創(chuàng)建一個服務(wù)工廠類,它將綁定到服務(wù)器的URL。這將是我們HTML中引用的services.js文件,它將進入app文件夾:<\/p>\n

      \n\n\n  \n  \n  \n  AngularJS - SignalR - ServiceDashboard<\/title>\n  <link rel=\"stylesheet\" href=\"Content\/bootstrap.min.css\" \/>\n  <link rel=\"stylesheet\" href=\"Content\/epoch.min.css\" \/>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n<\/head>\n<body ng-app=\"angularServiceDashboard\">
      <h1><a href="http://www.miracleart.cn/">国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂</a></h1>\n\n<\/body>\n<\/html><\/pre>\n<p>這段代碼使用了流行的on和off(這里不需要off)訂閱模式,并通過使用Angular工廠封裝了與我們應(yīng)用程序的SignalR的所有通信。<\/p>\n<p>這段代碼乍一看可能有點讓人不知所措,但當我們構(gòu)建控制器時,您會更好地理解它。它所做的只是獲取后端SignalR服務(wù)器的URL和SignalR中心名稱。(在SignalR中,您可以在同一服務(wù)器中使用多個中心來推送數(shù)據(jù)。)<\/p>\n<p>此外,這段代碼允許SignalR服務(wù)器(位于其他地方的某個盒子中)通過on方法調(diào)用我們的應(yīng)用程序。它允許我們的應(yīng)用程序通過invoke方法調(diào)用SignalR服務(wù)器內(nèi)部的函數(shù)。<\/p>\n<p>接下來,我們需要我們的控制器,它將把我們的數(shù)據(jù)從服務(wù)綁定到我們的作用域。讓我們在我們的app文件夾中創(chuàng)建一個名為controllers.js的文件。<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\nvar app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);\napp.value('backendServerUrl', 'http:\/\/sitepointsignal.cloudapp.net\/');<\/pre>\n<p>此控制器在這里做了一些事情。它創(chuàng)建了我們的Angular服務(wù)對象并將其綁定一個回調(diào)函數(shù),以便服務(wù)器在我們的控制器中調(diào)用某些內(nèi)容。<\/p>\n<p>您會看到,每次服務(wù)器回調(diào)我們時,我們都會遍歷服務(wù)器返回的JSON數(shù)組。然后我們?yōu)槊糠N性能類型都有一個switch語句?,F(xiàn)在,我們將設(shè)置RAM,然后返回并填充其余部分。<\/p>\n<p>至于我們的指令,我們實際上只需要一個用于我們的Epoch圖表。我們將使用一個名為ng-epoch.js的開源指令,我們在我們的index.html存根文件中已經(jīng)對其進行了引用。<\/p>\n<p>我們可以將所有這些圖表拆分為不同的指令,使用一些模板并使用UI-Router,但是為了本教程的簡單起見,我們將把所有視圖都放在我們的index.html文件中。<\/p>\n<p>現(xiàn)在讓我們將我們的視圖添加到index.html文件中。我們可以通過在body標簽下添加以下內(nèi)容來實現(xiàn):<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\napp.factory('backendHubProxy', ['$rootScope', 'backendServerUrl', \n  function ($rootScope, backendServerUrl) {\n\n    function backendFactory(serverUrl, hubName) {\n      var connection = $.hubConnection(backendServerUrl);\n      var proxy = connection.createHubProxy(hubName);\n\n      connection.start().done(function () { });\n\n      return {\n        on: function (eventName, callback) {\n              proxy.on(eventName, function (result) {\n                $rootScope.$apply(function () {\n                  if (callback) {\n                    callback(result);\n                  }\n                 });\n               });\n             },\n        invoke: function (methodName, callback) {\n                  proxy.invoke(methodName)\n                  .done(function (result) {\n                    $rootScope.$apply(function () {\n                      if (callback) {\n                        callback(result);\n                      }\n                    });\n                  });\n                }\n      };\n    };\n\n    return backendFactory;\n}]);<\/pre>\n<p>這將簡單地創(chuàng)建一個位置,讓服務(wù)器將RAM數(shù)據(jù)推回。數(shù)據(jù)將首先進入我們的服務(wù),然后進入控制器,最后進入視圖。<\/p>\n<p>它應(yīng)該看起來像這樣:<\/p><p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/000\/174002671842831.jpg\" alt=\"Build a Real-time SignalR Dashboard with AngularJS \" \/>現(xiàn)在讓我們添加一些圖表,這正是我們真正想要做的。我們將為epoch.js時間線添加一個名為timestamp的變量。我們還將添加一個名為chartEntry的數(shù)組,我們將將其綁定到我們的epoch.ng指令。<\/p>\n<pre><code>root\n    app     (Angular應(yīng)用程序特定的JavaScript)\n    Content (CSS等)\n    Scripts (引用的JavaScript等)\n    ...\n    index.html<\/code><\/pre>\n<p>然后讓我們映射switch語句中的數(shù)據(jù)并添加其余所需的epoch.js數(shù)據(jù)項。當然,我們可以進一步分解它(例如,使用更多函數(shù)和過濾器),但為了本教程的簡單起見,我們將保持簡單。<\/p>\n<pre class='brush:php;toolbar:false;'><!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>AngularJS - SignalR - ServiceDashboard<\/title>\n  <link rel=\"stylesheet\" href=\"Content\/bootstrap.min.css\" \/>\n  <link rel=\"stylesheet\" href=\"Content\/epoch.min.css\" \/>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n<\/head>\n<body ng-app=\"angularServiceDashboard\">\n\n<\/body>\n<\/html><\/pre>\n<p>我們的控制器看起來更完善了。我們在作用域中添加了一個realtimeAreaFeed,我們將通過ng-epoch指令將其綁定到我們的視圖,并且我們還在作用域中添加了areaAxes,它決定了區(qū)域圖的布局。<\/p>\n<p>現(xiàn)在讓我們將指令添加到index.html并顯示傳入的CPU值數(shù)據(jù):<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\nvar app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);\napp.value('backendServerUrl', 'http:\/\/sitepointsignal.cloudapp.net\/');<\/pre>\n<p>chart-class指的是D3.js的顏色方案,chart-height是您猜測的內(nèi)容,chart-stream是從SignalR服務(wù)器返回的數(shù)據(jù)。<\/p>\n<p>有了它,我們應(yīng)該看到圖表實時出現(xiàn):<\/p>\n<p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/000\/174002671985790.jpg\" alt=\"Build a Real-time SignalR Dashboard with AngularJS \" \/>現(xiàn)在讓我們將大量數(shù)據(jù)點連接到此圖表,并從n3-pie框架添加另一個圖表(因為誰不喜歡餅圖?。?。<\/p>\n<p>要從n3-pie框架添加餅圖,只需將以下內(nèi)容添加到我們的控制器中:<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\napp.factory('backendHubProxy', ['$rootScope', 'backendServerUrl', \n  function ($rootScope, backendServerUrl) {\n\n    function backendFactory(serverUrl, hubName) {\n      var connection = $.hubConnection(backendServerUrl);\n      var proxy = connection.createHubProxy(hubName);\n\n      connection.start().done(function () { });\n\n      return {\n        on: function (eventName, callback) {\n              proxy.on(eventName, function (result) {\n                $rootScope.$apply(function () {\n                  if (callback) {\n                    callback(result);\n                  }\n                 });\n               });\n             },\n        invoke: function (methodName, callback) {\n                  proxy.invoke(methodName)\n                  .done(function (result) {\n                    $rootScope.$apply(function () {\n                      if (callback) {\n                        callback(result);\n                      }\n                    });\n                  });\n                }\n      };\n    };\n\n    return backendFactory;\n}]);<\/pre>\n<p>當然,該值將由SignalR服務(wù)器更新。您可以在我們控制器的完整代碼中看到這一點。<\/p>\n<p>我們還應(yīng)該花點時間考慮一下我們視圖的完整代碼。<\/p>\n<p>我們應(yīng)該在屏幕上看到以下數(shù)據(jù):<\/p>\n<p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/000\/174002672079098.jpg\" alt=\"Build a Real-time SignalR Dashboard with AngularJS \" \/>我們已經(jīng)看到Angular可以非常輕松地連接到SignalR——只需在AngularJS服務(wù)或工廠中插入端點即可。AngularJS工廠是一種與SignalR通信的封裝機制?!敖Y(jié)合”后,誰知道AngularJS和.NET會如此完美地協(xié)同工作?<\/p>\n<h2>服務(wù)器的核心方面<\/h2>\n<p>我將介紹一些.NET代碼,這些代碼允許在后端進行此通信。(您可以在此處找到源代碼。)<\/p>\n<p>首先,要開始構(gòu)建服務(wù)器代碼,您需要在Visual Studio解決方案中運行SignalR。為此,只需按照ASP.NET上的優(yōu)秀教程即可運行基本的SignalR解決方案。(這是最簡單的。)<\/p>\n<p>運行后,將C# Hub類更改為以下內(nèi)容:<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\napp.controller('PerformanceDataController', ['$scope', 'backendHubProxy',\n  function ($scope, backendHubProxy) {\n    console.log('trying to connect to service')\n    var performanceDataHub = backendHubProxy(backendHubProxy.defaultServer, 'performanceHub');\n    console.log('connected to service')\n    $scope.currentRamNumber = 68;\n\n    performanceDataHub.on('broadcastPerformance', function (data) {\n      data.forEach(function (dataItem) {\n        switch(dataItem.categoryName) {\n          case 'Processor':\n            break;\n          case 'Memory':\n            $scope.currentRamNumber = dataItem.value;\n            break;\n          case 'Network In':\n            break;\n          case 'Network Out':\n            break;\n          case 'Disk Read Bytes\/Sec':\n            break;\n          case 'Disk Write Bytes\/Sec':\n            break;\n          default:\n            \/\/default code block\n            break;           \n        }\n      });     \n    });\n  }\n]);<\/pre>\n<p>更改Hub類后,Visual Studio將報錯,您需要添加一個性能模型(由于Json.NET,它在服務(wù)器推送時會自動轉(zhuǎn)換為JSON):<\/p><pre><code>root\n    app     (Angular應(yīng)用程序特定的JavaScript)\n    Content (CSS等)\n    Scripts (引用的JavaScript等)\n    ...\n    index.html<\/code><\/pre>\n<p>JsonProperty元數(shù)據(jù)只是告訴Json.NET在為此模型轉(zhuǎn)換為JSON時自動將屬性名稱轉(zhuǎn)換為小寫。JavaScript喜歡小寫。<\/p>\n<p>讓我們添加一個PerformanceEngine類,它將通過SignalR將真實性能數(shù)據(jù)推送到任何偵聽的客戶端。該引擎通過異步后臺線程通過SignalR向任何偵聽的客戶端發(fā)送這些消息。<\/p>\n<p>由于其長度,您可以在我們的GitHub存儲庫中找到代碼。<\/p>\n<p>此代碼基本上在每次while迭代中將一系列性能指標推送到任何已訂閱的客戶端。這些性能指標被注入到構(gòu)造函數(shù)中。從服務(wù)器推送的速度在構(gòu)造函數(shù)參數(shù)pollIntervalMillis上設(shè)置。<\/p>\n<p>請注意,如果您使用OWIN作為自托管來托管SignalR,這將運行良好,如果您使用Web工作線程,它也應(yīng)該運行良好。<\/p>\n<p>最后要做的事情當然是在服務(wù)的OnStart()或Startup類中的某個地方啟動后臺線程。<\/p>\n<pre class='brush:php;toolbar:false;'><!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>AngularJS - SignalR - ServiceDashboard<\/title>\n  <link rel=\"stylesheet\" href=\"Content\/bootstrap.min.css\" \/>\n  <link rel=\"stylesheet\" href=\"Content\/epoch.min.css\" \/>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n  <??>\n  <??>\n  <??>\n  <??>\n\n<\/head>\n<body ng-app=\"angularServiceDashboard\">\n\n<\/body>\n<\/html><\/pre>\n<p>啟動后臺線程的兩行代碼(正如您猜到的那樣)是我們實例化PerformanceEngine和調(diào)用OnPerformanceMonitor()的地方。<\/p>\n<p>現(xiàn)在,我知道您可能認為我正在隨機化來自服務(wù)器的數(shù)據(jù),這是事實。但是要推送真實指標,只需使用System.Diagnostics庫和Windows提供的PerformanceCounter即可。我試圖保持簡單,但這就是代碼的樣子:<\/p>\n<pre class='brush:php;toolbar:false;'>'use strict';\n\nvar app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);\napp.value('backendServerUrl', 'http:\/\/sitepointsignal.cloudapp.net\/');<\/pre>\n<h2>結(jié)論<\/h2>\n<p>我們已經(jīng)了解了如何通過Angular使用SignalR數(shù)據(jù),并且我們已經(jīng)將該數(shù)據(jù)連接到Angular端的實時圖表框架。<\/p>\n<p>此處顯示客戶端最終版本的演示,您可以從此處獲取代碼。<\/p>\n<p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/000\/174002672199955.jpg\" alt=\"Build a Real-time SignalR Dashboard with AngularJS \">此處顯示服務(wù)器最終版本的演示,您可以從此處獲取代碼。<\/p>\n<p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/000\/174002672259072.jpg\" alt=\"Build a Real-time SignalR Dashboard with AngularJS \">我希望您喜歡這個演練。如果您嘗試過類似的方法,請在評論中告訴我們!<\/p>\n<h2>使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答 (FAQ)<\/h2>\n<h3>如何在AngularJS中設(shè)置SignalR?<\/h3>\n<p>在AngularJS中設(shè)置SignalR涉及幾個步驟。首先,您需要使用NuGet或npm安裝SignalR庫。安裝后,您可以在服務(wù)器上創(chuàng)建一個新的SignalR中心。此中心將負責發(fā)送和接收消息。在客戶端,您需要引用SignalR JavaScript庫并創(chuàng)建到您的中心的連接。然后,您可以啟動連接并定義處理傳入消息的函數(shù)。<\/p>\n<h3>如何處理SignalR中的連接錯誤?<\/h3>\n<p>SignalR提供了一種處理連接錯誤的內(nèi)置機制。您可以使用中心連接上的.error()函數(shù)來定義一個回調(diào)函數(shù),該函數(shù)將在發(fā)生錯誤時調(diào)用。此回調(diào)函數(shù)可以向用戶顯示錯誤消息或嘗試重新連接到中心。<\/p>\n<h3>我可以將SignalR與其他JavaScript框架一起使用嗎?<\/h3>\n<p>是的,SignalR可以與任何支持AJAX和WebSockets的JavaScript框架一起使用。這包括流行的框架,如React、Vue.js和Angular。您只需要將SignalR JavaScript庫包含在您的項目中并像在任何其他JavaScript應(yīng)用程序中一樣創(chuàng)建一個中心連接即可。<\/p>\n<h3>如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端?<\/h3>\n<p>要將消息從服務(wù)器發(fā)送到客戶端,您可以使用中心的Clients屬性。此屬性提供方法,用于將消息發(fā)送到所有連接的客戶端、特定客戶端或客戶端組。您可以從服務(wù)器代碼的任何部分調(diào)用這些方法,以將實時更新發(fā)送到您的客戶端。<\/p>\n<h3>如何保護我的SignalR應(yīng)用程序?<\/h3>\n<p>SignalR提供了幾個保護應(yīng)用程序的選項。您可以使用[Authorize]屬性來限制對您的中心和中心方法的訪問。您還可以使用Global.asax文件中的MapHubs()方法為您的中心指定自定義授權(quán)器。此外,您可以使用SSL來加密SignalR流量并防止竊聽。<\/p>\n<h3>如何處理SignalR中的斷開連接?<\/h3>\n<p>SignalR會自動處理斷開連接并嘗試重新連接。但是,您也可以使用中心連接上的.disconnected()函數(shù)手動處理斷開連接。此函數(shù)允許您定義一個回調(diào)函數(shù),該函數(shù)將在連接丟失時調(diào)用。<\/p>\n<h3>我可以在非.NET服務(wù)器上使用SignalR嗎?<\/h3>\n<p>SignalR是一個.NET庫,旨在與.NET服務(wù)器一起使用。但是,可以通過使用兼容的WebSocket庫在非.NET服務(wù)器上使用SignalR。您需要在服務(wù)器上實現(xiàn)SignalR協(xié)議并自行處理連接和消息傳遞邏輯。<\/p>\n<h3>如何測試我的SignalR應(yīng)用程序?<\/h3>\n<p>您可以使用Postman或Fiddler等工具向您的中心發(fā)送HTTP請求并驗證響應(yīng)來測試您的SignalR應(yīng)用程序。您還可以為您的中心方法和客戶端函數(shù)編寫單元測試。<\/p>\n<h3>我可以在移動應(yīng)用程序中使用SignalR嗎?<\/h3>\n<p>是的,您可以在移動應(yīng)用程序中使用SignalR。SignalR JavaScript庫可以在使用Cordova或Ionic構(gòu)建的混合移動應(yīng)用程序中使用。對于原生移動應(yīng)用程序,iOS和Android都提供了SignalR客戶端。<\/p>\n<h3>如何擴展我的SignalR應(yīng)用程序?<\/h3>\n<p>SignalR提供了幾個擴展應(yīng)用程序的選項。您可以使用Azure SignalR服務(wù),這是一個完全托管的服務(wù),它為您處理所有SignalR連接。您還可以使用后端,這是一個軟件層,用于在多個服務(wù)器之間分發(fā)消息。<\/p>"}	</script>
      	
      <meta http-equiv="Cache-Control" content="no-transform" />
      <meta http-equiv="Cache-Control" content="no-siteapp" />
      <script>var V_PATH="/";window.onerror=function(){ return true; };</script>
      </head>
      
      <body data-commit-time="2023-12-28T14:50:12+08:00" class="editor_body body2_2">
      	<link rel="stylesheet" type="text/css" href="/static/csshw/stylehw.css">
      <header>
          <div   id="377j5v51b"   class="head">
              <div   id="377j5v51b"   class="haed_left">
                  <div   id="377j5v51b"   class="haed_logo">
                      <a href="http://www.miracleart.cn/zh/" title="" class="haed_logo_a">
                          <img src="/static/imghw/logo.png" alt="" class="haed_logoimg">
                      </a>
                  </div>
                  <div   id="377j5v51b"   class="head_nav">
                      <div   id="377j5v51b"   class="head_navs">
                          <a href="javascript:;" title="社區(qū)" class="head_nava head_nava-template1">社區(qū)</a>
                          <div   class="377j5v51b"   id="dropdown-template1" style="display: none;">
                              <div   id="377j5v51b"   class="languagechoose">
                                  <a href="http://www.miracleart.cn/zh/article.html" title="文章" class="languagechoosea on">文章</a>
                                  <a href="http://www.miracleart.cn/zh/faq/zt" title="合集" class="languagechoosea">合集</a>
                                  <a href="http://www.miracleart.cn/zh/wenda.html" title="問答" class="languagechoosea">問答</a>
                              </div>
                          </div>
                      </div>
      
                      <div   id="377j5v51b"   class="head_navs">
                          <a href="javascript:;" title="學(xué)習" class="head_nava head_nava-template1_1">學(xué)習</a>
                          <div   class="377j5v51b"   id="dropdown-template1_1" style="display: none;">
                              <div   id="377j5v51b"   class="languagechoose">
                                  <a href="http://www.miracleart.cn/zh/course.html" title="課程" class="languagechoosea on">課程</a>
                                  <a href="http://www.miracleart.cn/zh/dic/" title="編程詞典" class="languagechoosea">編程詞典</a>
                              </div>
                          </div>
                      </div>
      
                      <div   id="377j5v51b"   class="head_navs">
                          <a href="javascript:;" title="工具庫" class="head_nava head_nava-template1_2">工具庫</a>
                          <div   class="377j5v51b"   id="dropdown-template1_2" style="display: none;">
                              <div   id="377j5v51b"   class="languagechoose">
                                  <a href="http://www.miracleart.cn/zh/toolset/development-tools" title="開發(fā)工具" class="languagechoosea on">開發(fā)工具</a>
                                  <a href="http://www.miracleart.cn/zh/toolset/website-source-code" title="網(wǎng)站源碼" class="languagechoosea">網(wǎng)站源碼</a>
                                  <a href="http://www.miracleart.cn/zh/toolset/php-libraries" title="PHP 庫" class="languagechoosea">PHP 庫</a>
                                  <a href="http://www.miracleart.cn/zh/toolset/js-special-effects" title="JS特效" class="languagechoosea on">JS特效</a>
                                  <a href="http://www.miracleart.cn/zh/toolset/website-materials" title="網(wǎng)站素材" class="languagechoosea on">網(wǎng)站素材</a>
                                  <a href="http://www.miracleart.cn/zh/toolset/extension-plug-ins" title="擴展插件" class="languagechoosea on">擴展插件</a>
                              </div>
                          </div>
                      </div>
      
                      <div   id="377j5v51b"   class="head_navs">
                          <a href="http://www.miracleart.cn/zh/ai" title="AI工具" class="head_nava head_nava-template1_3">AI工具</a>
                      </div>
      
                      <div   id="377j5v51b"   class="head_navs">
                          <a href="javascript:;" title="休閑" class="head_nava head_nava-template1_3">休閑</a>
                          <div   class="377j5v51b"   id="dropdown-template1_3" style="display: none;">
                              <div   id="377j5v51b"   class="languagechoose">
                                  <a href="http://www.miracleart.cn/zh/game" title="游戲下載" class="languagechoosea on">游戲下載</a>
                                  <a href="http://www.miracleart.cn/zh/mobile-game-tutorial/" title="游戲教程" class="languagechoosea">游戲教程</a>
      
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
                          <div   id="377j5v51b"   class="head_search">
                      <input id="key_words"  onkeydown="if (event.keyCode == 13) searchs('zh')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value="">
                      <a href="javascript:;" title="搜索"  onclick="searchs('zh')"><img src="/static/imghw/find.png" alt="搜索"></a>
                  </div>
                      <div   id="377j5v51b"   class="head_right">
                  <div   id="377j5v51b"   class="haed_language">
                      <a href="javascript:;" class="layui-btn haed_language_btn">簡體中文<i class="layui-icon layui-icon-triangle-d"></i></a>
                      <div   class="377j5v51b"   id="dropdown-template" style="display: none;">
                          <div   id="377j5v51b"   class="languagechoose">
                                                      <a href="javascript:;" title="簡體中文" class="languagechoosea">簡體中文</a>
                                                      <a href="javascript:setlang('en');" title="English" class="languagechoosea">English</a>
                                                      <a href="javascript:setlang('zh-tw');" title="繁體中文" class="languagechoosea">繁體中文</a>
                                                      <a href="javascript:setlang('ja');" title="日本語" class="languagechoosea">日本語</a>
                                                      <a href="javascript:setlang('ko');" title="???" class="languagechoosea">???</a>
                                                      <a href="javascript:setlang('ms');" title="Melayu" class="languagechoosea">Melayu</a>
                                                      <a href="javascript:setlang('fr');" title="Fran?ais" class="languagechoosea">Fran?ais</a>
                                                      <a href="javascript:setlang('de');" title="Deutsch" class="languagechoosea">Deutsch</a>
                                                  </div>
                      </div>
                  </div>
                  <span id="377j5v51b"    class="head_right_line"></span>
                                  <div style="display: block;" id="login" class="haed_login ">
                          <a href="javascript:;"  title="Login" class="haed_logina ">Login</a>
                      </div>
                      <div style="display: block;" id="reg" class="head_signup login">
                          <a href="javascript:;"  title="singup" class="head_signupa">singup</a>
                      </div>
                  
              </div>
          </div>
      </header>
      
      	
      	<main>
      		<div   id="377j5v51b"   class="Article_Details_main">
      			<div   id="377j5v51b"   class="Article_Details_main1">
      							<div   id="377j5v51b"   class="Article_Details_main1L">
      					<div   id="377j5v51b"   class="Article_Details_main1Lmain" id="Article_Details_main1Lmain">
      						<div   id="377j5v51b"   class="Article_Details_main1L1">目錄</div>
      						<div   id="377j5v51b"   class="Article_Details_main1L2" id="Article_Details_main1L2">
      							<!-- 左側(cè)懸浮,文章定位標題1 id="Article_Details_main1L2s_1"-->
      															<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#關(guān)鍵要點" title="關(guān)鍵要點" >關(guān)鍵要點</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#技術(shù)架構(gòu)" title="技術(shù)架構(gòu)" >技術(shù)架構(gòu)</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#客戶端" title="客戶端" >客戶端</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#服務(wù)器端" title="服務(wù)器端" >服務(wù)器端</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#核心內(nèi)容" title="核心內(nèi)容" >核心內(nèi)容</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#開始設(shè)置" title="開始設(shè)置" >開始設(shè)置</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#使用純文本文件進行設(shè)置" title="使用純文本文件進行設(shè)置" >使用純文本文件進行設(shè)置</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#主要依賴項" title="主要依賴項" >主要依賴項</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#使用Visual-Studio進行設(shè)置" title="使用Visual Studio進行設(shè)置" >使用Visual Studio進行設(shè)置</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#讓我們編寫我們的應(yīng)用程序" title="讓我們編寫我們的應(yīng)用程序" >讓我們編寫我們的應(yīng)用程序</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#服務(wù)器的核心方面" title="服務(wù)器的核心方面" >服務(wù)器的核心方面</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#結(jié)論" title="結(jié)論" >結(jié)論</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答-FAQ" title="使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答 (FAQ)" >使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答 (FAQ)</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何在AngularJS中設(shè)置SignalR" title="如何在AngularJS中設(shè)置SignalR?" >如何在AngularJS中設(shè)置SignalR?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何處理SignalR中的連接錯誤" title="如何處理SignalR中的連接錯誤?" >如何處理SignalR中的連接錯誤?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#我可以將SignalR與其他JavaScript框架一起使用嗎" title="我可以將SignalR與其他JavaScript框架一起使用嗎?" >我可以將SignalR與其他JavaScript框架一起使用嗎?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端" title="如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端?" >如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何保護我的SignalR應(yīng)用程序" title="如何保護我的SignalR應(yīng)用程序?" >如何保護我的SignalR應(yīng)用程序?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何處理SignalR中的斷開連接" title="如何處理SignalR中的斷開連接?" >如何處理SignalR中的斷開連接?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#我可以在非-NET服務(wù)器上使用SignalR嗎" title="我可以在非.NET服務(wù)器上使用SignalR嗎?" >我可以在非.NET服務(wù)器上使用SignalR嗎?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何測試我的SignalR應(yīng)用程序" title="如何測試我的SignalR應(yīng)用程序?" >如何測試我的SignalR應(yīng)用程序?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#我可以在移動應(yīng)用程序中使用SignalR嗎" title="我可以在移動應(yīng)用程序中使用SignalR嗎?" >我可以在移動應(yīng)用程序中使用SignalR嗎?</a>
      								</div>
      																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
      									<a href="#如何擴展我的SignalR應(yīng)用程序" title="如何擴展我的SignalR應(yīng)用程序?" >如何擴展我的SignalR應(yīng)用程序?</a>
      								</div>
      														</div>
      					</div>
      				</div>
      							<div   id="377j5v51b"   class="Article_Details_main1M">
      					<div   id="377j5v51b"   class="phpgenera_Details_mainL1">
      						<a href="http://www.miracleart.cn/zh/" title="首頁"
      							class="phpgenera_Details_mainL1a">首頁</a>
      						<img src="/static/imghw/top_right.png" alt="" />
      												<a href="http://www.miracleart.cn/zh/web-designer.html"
      							class="phpgenera_Details_mainL1a">web前端</a>
      						<img src="/static/imghw/top_right.png" alt="" />
      												<a href="http://www.miracleart.cn/zh/js-tutorial.html"
      							class="phpgenera_Details_mainL1a">js教程</a>
      						<img src="/static/imghw/top_right.png" alt="" />
      						<span>用AngularJS構(gòu)建實時信號儀表板</span>
      					</div>
      					
      					<div   id="377j5v51b"   class="Articlelist_txts">
      						<div   id="377j5v51b"   class="Articlelist_txts_info">
      							<h1 class="Articlelist_txts_title">用AngularJS構(gòu)建實時信號儀表板</h1>
      							<div   id="377j5v51b"   class="Articlelist_txts_info_head">
      								<div   id="377j5v51b"   class="author_info">
      									<a href="http://www.miracleart.cn/zh/member/1468497.html"  class="author_avatar">
      									<img class="lazy"  data-src="https://img.php.cn/upload/avatar/000/000/001/66ea80bad5190693.png" src="/static/imghw/default1.png" alt="William Shakespeare">
      									</a>
      									<div   id="377j5v51b"   class="author_detail">
      																			<a href="http://www.miracleart.cn/zh/member/1468497.html" class="author_name">William Shakespeare</a>
                                      										</div>
      								</div>
                      			</div>
      							<span id="377j5v51b"    class="Articlelist_txts_time">Feb 20, 2025 pm	 12:45 PM</span>
      														
      						</div>
      					</div>
      					<hr />
      					<div   id="377j5v51b"   class="article_main php-article">
      						<div   id="377j5v51b"   class="article-list-left detail-content-wrap content">
      						<ins class="adsbygoogle"
      							style="display:block; text-align:center;"
      							data-ad-layout="in-article"
      							data-ad-format="fluid"
      							data-ad-client="ca-pub-5902227090019525"
      							data-ad-slot="3461856641">
      						</ins>
      						
      
      					<p>構(gòu)建實時服務(wù)監(jiān)控面板!</p>
      <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174002671380592.jpg" class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS ">我們的服務(wù)監(jiān)控面板將實時顯示真實數(shù)據(jù)。它將以近乎實時的、異步的、非阻塞的方式向我們展示服務(wù)器和微服務(wù)上發(fā)生的情況。</p>
      <p>點擊此處查看完整客戶端示例。</p>
      <p>觀看使用D3.js可視化數(shù)據(jù),用JavaScript闡述你的數(shù)據(jù)! <img src="/static/imghw/default1.png" data-src="https://img.php.cn/editor.sitepoint.com/wp-content/themes/sitepoint/assets/svg/play-icon.svg" class="lazy" alt="">觀看此課程 觀看此課程  此處展示服務(wù)器演示。</p>
      <p>我們將使用AngularJS框架和許多炫酷的實時圖表以及大量實時數(shù)據(jù)來構(gòu)建此監(jiān)控面板的簡化版本。我們還將使用.NET 4.5的SignalR和Web API庫構(gòu)建我們的服務(wù)。</p>
      <h2 id="關(guān)鍵要點">關(guān)鍵要點</h2>
      <ul>
      <li>利用AngularJS和SignalR創(chuàng)建一個實時監(jiān)控面板,異步且非阻塞地顯示服務(wù)器和微服務(wù)的活動。</li>
      <li>使用純文本文件或Visual Studio設(shè)置項目,依賴項包括AngularJS、jQuery、Bootstrap、SignalR以及各種圖表庫,如D3.js和Epoch。</li>
      <li>在服務(wù)器端實現(xiàn)SignalR中心來管理實時數(shù)據(jù)傳輸,利用.NET處理異步請求和向客戶端推送通知的能力。</li>
      <li>開發(fā)AngularJS服務(wù)和控制器來處理從SignalR中心接收的數(shù)據(jù),實時更新UI以反映服務(wù)器性能指標的變化。</li>
      <li>集成ng-epoch和n3-pie等圖表解決方案來直觀地表示數(shù)據(jù),增強監(jiān)控面板的交互性和用戶參與度。</li>
      </ul>
      <h2 id="技術(shù)架構(gòu)">技術(shù)架構(gòu)</h2>
      <h3 id="客戶端">客戶端</h3>
      <p>AngularJS開箱即用地強制執(zhí)行良好的應(yīng)用程序開發(fā)實踐。所有內(nèi)容都是注入的,這意味著依賴項的耦合度低。此外,Angular在視圖、模型和控制器之間具有良好的分離。</p>
      <p>Angular在這里補充了.NET,允許服務(wù)器端代碼保持小巧、易于管理和可測試。服務(wù)器端代碼僅用于發(fā)揮其優(yōu)勢——進行繁重的處理。</p>
      <h3 id="服務(wù)器端">服務(wù)器端</h3>
      <p>將SignalR與.NET 4.5的Web API一起使用與將Node.js與Socket.IO一起使用非常相似,并允許從服務(wù)器到訂閱客戶端進行相同類型的非阻塞、異步推送。SignalR在底層使用WebSockets,但因為它抽象了通信,所以在Angular內(nèi)部運行時,它將回退到客戶端瀏覽器支持的任何技術(shù)。(例如,對于舊版瀏覽器,它可能會回退到長輪詢。)</p>
      <p>此外,借助動態(tài)標簽和Json.NET的魔力,.NET框架將JavaScript視為一等公民。事實上,通過JavaScript使用Web API和SignalR技術(shù)通常比通過原生.NET客戶端更容易,因為它們是考慮到JavaScript而構(gòu)建的。</p>
      <h2 id="核心內(nèi)容">核心內(nèi)容</h2>
      <h3 id="開始設(shè)置">開始設(shè)置</h3>
      <p>本教程中使用的所有AngularJS代碼都可以在此處找到。</p>
      <p>我將介紹如何使用您最喜歡的文本編輯器和純文件夾以及Visual Studio來創(chuàng)建它,這取決于創(chuàng)建項目的工具。</p>
      <h3 id="使用純文本文件進行設(shè)置">使用純文本文件進行設(shè)置</h3>
      <p>文件夾和文件結(jié)構(gòu)如下所示:</p>
      <pre class="brush:php;toolbar:false"><code>root
          app     (Angular應(yīng)用程序特定的JavaScript)
          Content (CSS等)
          Scripts (引用的JavaScript等)
          ...
          index.html</code></pre>
      <h3 id="主要依賴項">主要依賴項</h3>
      <p>您需要下載以下文件:</p>
      <ul>
      <li>jQuery(選擇“下載壓縮的生產(chǎn)jQuery 2.1.1”鏈接)</li>
      <li>AngularJS(單擊大型“下載”選項,然后單擊Angular 1.3 的最新版本)</li>
      <li>Bootstrap(單擊“下載Bootstrap”選項)</li>
      <li>SignalR(單擊右側(cè)的“下載ZIP”按鈕)</li>
      <li>D3.js(單擊頁面中間的“d3.zip”鏈接)</li>
      <li>Epoch(單擊“下載v0.6.0鏈接”)</li>
      <li>ng-epoch(單擊右側(cè)的“下載ZIP”按鈕)</li>
      <li>n3-pie(單擊右側(cè)的“下載ZIP”按鈕)</li>
      </ul>
      <p>在我們的Scripts文件夾中,我們需要:</p>
      <ul>
      <li>jquery-2.1.1.min.js</li>
      <li>angular.min.js</li>
      <li>bootstrap.min.js</li>
      <li>jquery.signalR.min.js</li>
      <li>d3.min.js</li>
      <li>epoch.min.js</li>
      <li>pie-chart.min.js</li>
      </ul>
      <p>在我們的Content文件夾中:</p>
      <ul>
      <li>bootstrap.min.css</li>
      <li>epoch.min.css</li>
      </ul>
      <h3 id="使用Visual-Studio進行設(shè)置">使用Visual Studio進行設(shè)置</h3>
      <p>如果您覺得文本文件過于簡單,則通過Visual Studio進行設(shè)置非常簡單。</p>
      <p>只需通過轉(zhuǎn)到文件 -> 新建 -> 項目,然后選擇Web作為模板類型來設(shè)置一個空的Web應(yīng)用程序。</p>
      <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174002671581952.jpg" class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS ">然后只需右鍵單擊項目,轉(zhuǎn)到管理Nuget包,搜索并下載jQuery、AngularJS、Bootstrap、D3和SignalR JavaScript客戶端。</p>
      <p>下載并安裝這些后,您應(yīng)該在Scripts和Contents文件夾中看到它們。此外,在已安裝的Nuget包下,您將看到以下內(nèi)容:</p>
      <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174002671658886.jpg" class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS ">最后,Nuget不包含Epoch、ng-epoch和n3圖表庫,因此您需要手動添加它們。只需按照上一節(jié)中詳細介紹的步驟即可獲取這些庫。</p>
      <h2 id="讓我們編寫我們的應(yīng)用程序">讓我們編寫我們的應(yīng)用程序</h2>
      <p>現(xiàn)在我們準備編寫一些代碼了。</p>
      <p>首先,讓我們創(chuàng)建我們的基本index.html文件,它將容納我們的Angular JavaScript代碼。</p>
      <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AngularJS - SignalR - ServiceDashboard</title>
        <link rel="stylesheet" href="Content/bootstrap.min.css" />
        <link rel="stylesheet" href="Content/epoch.min.css" />
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
      </head>
      <body ng-app="angularServiceDashboard">
      
      </body>
      </html></pre>
      <p>這里有一些事情需要注意。首先,我們添加了所有依賴項以便它們加載。其次,我們引用了一些尚不存在的新文件(app文件夾中的所有文件)。我們接下來將編寫這些文件。</p>
      <p>讓我們進入我們的app文件夾并創(chuàng)建我們的app.js文件。這是一個非常簡單的文件。</p><pre class="brush:php;toolbar:false"><code>root
          app     (Angular應(yīng)用程序特定的JavaScript)
          Content (CSS等)
          Scripts (引用的JavaScript等)
          ...
          index.html</code></pre>
      <p>此文件為我們做了幾件事。它設(shè)置了我們的主應(yīng)用程序模塊angularServiceDashboard,并注入了兩個外部引用——ng.epoch(這是我們的Epoch.js Angular指令)和n3-pie-chart(這是一個為Angular制作的、結(jié)構(gòu)良好的圖表庫)。</p>
      <p>如果您注意到,我們還為backendServerUrl注入了一個值,它當然托管在其他地方,我們計劃在這里使用它。</p>
      <p>讓我們創(chuàng)建一個服務(wù)工廠類,它將綁定到服務(wù)器的URL。這將是我們HTML中引用的services.js文件,它將進入app文件夾:</p>
      <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AngularJS - SignalR - ServiceDashboard</title>
        <link rel="stylesheet" href="Content/bootstrap.min.css" />
        <link rel="stylesheet" href="Content/epoch.min.css" />
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
      </head>
      <body ng-app="angularServiceDashboard">
      
      </body>
      </html></pre>
      <p>這段代碼使用了流行的on和off(這里不需要off)訂閱模式,并通過使用Angular工廠封裝了與我們應(yīng)用程序的SignalR的所有通信。</p>
      <p>這段代碼乍一看可能有點讓人不知所措,但當我們構(gòu)建控制器時,您會更好地理解它。它所做的只是獲取后端SignalR服務(wù)器的URL和SignalR中心名稱。(在SignalR中,您可以在同一服務(wù)器中使用多個中心來推送數(shù)據(jù)。)</p>
      <p>此外,這段代碼允許SignalR服務(wù)器(位于其他地方的某個盒子中)通過on方法調(diào)用我們的應(yīng)用程序。它允許我們的應(yīng)用程序通過invoke方法調(diào)用SignalR服務(wù)器內(nèi)部的函數(shù)。</p>
      <p>接下來,我們需要我們的控制器,它將把我們的數(shù)據(jù)從服務(wù)綁定到我們的作用域。讓我們在我們的app文件夾中創(chuàng)建一個名為controllers.js的文件。</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      var app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);
      app.value('backendServerUrl', 'http://sitepointsignal.cloudapp.net/');</pre>
      <p>此控制器在這里做了一些事情。它創(chuàng)建了我們的Angular服務(wù)對象并將其綁定一個回調(diào)函數(shù),以便服務(wù)器在我們的控制器中調(diào)用某些內(nèi)容。</p>
      <p>您會看到,每次服務(wù)器回調(diào)我們時,我們都會遍歷服務(wù)器返回的JSON數(shù)組。然后我們?yōu)槊糠N性能類型都有一個switch語句?,F(xiàn)在,我們將設(shè)置RAM,然后返回并填充其余部分。</p>
      <p>至于我們的指令,我們實際上只需要一個用于我們的Epoch圖表。我們將使用一個名為ng-epoch.js的開源指令,我們在我們的index.html存根文件中已經(jīng)對其進行了引用。</p>
      <p>我們可以將所有這些圖表拆分為不同的指令,使用一些模板并使用UI-Router,但是為了本教程的簡單起見,我們將把所有視圖都放在我們的index.html文件中。</p>
      <p>現(xiàn)在讓我們將我們的視圖添加到index.html文件中。我們可以通過在body標簽下添加以下內(nèi)容來實現(xiàn):</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      app.factory('backendHubProxy', ['$rootScope', 'backendServerUrl', 
        function ($rootScope, backendServerUrl) {
      
          function backendFactory(serverUrl, hubName) {
            var connection = $.hubConnection(backendServerUrl);
            var proxy = connection.createHubProxy(hubName);
      
            connection.start().done(function () { });
      
            return {
              on: function (eventName, callback) {
                    proxy.on(eventName, function (result) {
                      $rootScope.$apply(function () {
                        if (callback) {
                          callback(result);
                        }
                       });
                     });
                   },
              invoke: function (methodName, callback) {
                        proxy.invoke(methodName)
                        .done(function (result) {
                          $rootScope.$apply(function () {
                            if (callback) {
                              callback(result);
                            }
                          });
                        });
                      }
            };
          };
      
          return backendFactory;
      }]);</pre>
      <p>這將簡單地創(chuàng)建一個位置,讓服務(wù)器將RAM數(shù)據(jù)推回。數(shù)據(jù)將首先進入我們的服務(wù),然后進入控制器,最后進入視圖。</p>
      <p>它應(yīng)該看起來像這樣:</p><p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/174002671842831.jpg"  class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS " />現(xiàn)在讓我們添加一些圖表,這正是我們真正想要做的。我們將為epoch.js時間線添加一個名為timestamp的變量。我們還將添加一個名為chartEntry的數(shù)組,我們將將其綁定到我們的epoch.ng指令。</p>
      <pre class="brush:php;toolbar:false"><code>root
          app     (Angular應(yīng)用程序特定的JavaScript)
          Content (CSS等)
          Scripts (引用的JavaScript等)
          ...
          index.html</code></pre>
      <p>然后讓我們映射switch語句中的數(shù)據(jù)并添加其余所需的epoch.js數(shù)據(jù)項。當然,我們可以進一步分解它(例如,使用更多函數(shù)和過濾器),但為了本教程的簡單起見,我們將保持簡單。</p>
      <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AngularJS - SignalR - ServiceDashboard</title>
        <link rel="stylesheet" href="Content/bootstrap.min.css" />
        <link rel="stylesheet" href="Content/epoch.min.css" />
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
      </head>
      <body ng-app="angularServiceDashboard">
      
      </body>
      </html></pre>
      <p>我們的控制器看起來更完善了。我們在作用域中添加了一個realtimeAreaFeed,我們將通過ng-epoch指令將其綁定到我們的視圖,并且我們還在作用域中添加了areaAxes,它決定了區(qū)域圖的布局。</p>
      <p>現(xiàn)在讓我們將指令添加到index.html并顯示傳入的CPU值數(shù)據(jù):</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      var app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);
      app.value('backendServerUrl', 'http://sitepointsignal.cloudapp.net/');</pre>
      <p>chart-class指的是D3.js的顏色方案,chart-height是您猜測的內(nèi)容,chart-stream是從SignalR服務(wù)器返回的數(shù)據(jù)。</p>
      <p>有了它,我們應(yīng)該看到圖表實時出現(xiàn):</p>
      <p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/174002671985790.jpg"  class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS " />現(xiàn)在讓我們將大量數(shù)據(jù)點連接到此圖表,并從n3-pie框架添加另一個圖表(因為誰不喜歡餅圖?。?/p>
      <p>要從n3-pie框架添加餅圖,只需將以下內(nèi)容添加到我們的控制器中:</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      app.factory('backendHubProxy', ['$rootScope', 'backendServerUrl', 
        function ($rootScope, backendServerUrl) {
      
          function backendFactory(serverUrl, hubName) {
            var connection = $.hubConnection(backendServerUrl);
            var proxy = connection.createHubProxy(hubName);
      
            connection.start().done(function () { });
      
            return {
              on: function (eventName, callback) {
                    proxy.on(eventName, function (result) {
                      $rootScope.$apply(function () {
                        if (callback) {
                          callback(result);
                        }
                       });
                     });
                   },
              invoke: function (methodName, callback) {
                        proxy.invoke(methodName)
                        .done(function (result) {
                          $rootScope.$apply(function () {
                            if (callback) {
                              callback(result);
                            }
                          });
                        });
                      }
            };
          };
      
          return backendFactory;
      }]);</pre>
      <p>當然,該值將由SignalR服務(wù)器更新。您可以在我們控制器的完整代碼中看到這一點。</p>
      <p>我們還應(yīng)該花點時間考慮一下我們視圖的完整代碼。</p>
      <p>我們應(yīng)該在屏幕上看到以下數(shù)據(jù):</p>
      <p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/000/000/174002672079098.jpg"  class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS " />我們已經(jīng)看到Angular可以非常輕松地連接到SignalR——只需在AngularJS服務(wù)或工廠中插入端點即可。AngularJS工廠是一種與SignalR通信的封裝機制?!敖Y(jié)合”后,誰知道AngularJS和.NET會如此完美地協(xié)同工作?</p>
      <h2 id="服務(wù)器的核心方面">服務(wù)器的核心方面</h2>
      <p>我將介紹一些.NET代碼,這些代碼允許在后端進行此通信。(您可以在此處找到源代碼。)</p>
      <p>首先,要開始構(gòu)建服務(wù)器代碼,您需要在Visual Studio解決方案中運行SignalR。為此,只需按照ASP.NET上的優(yōu)秀教程即可運行基本的SignalR解決方案。(這是最簡單的。)</p>
      <p>運行后,將C# Hub類更改為以下內(nèi)容:</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      app.controller('PerformanceDataController', ['$scope', 'backendHubProxy',
        function ($scope, backendHubProxy) {
          console.log('trying to connect to service')
          var performanceDataHub = backendHubProxy(backendHubProxy.defaultServer, 'performanceHub');
          console.log('connected to service')
          $scope.currentRamNumber = 68;
      
          performanceDataHub.on('broadcastPerformance', function (data) {
            data.forEach(function (dataItem) {
              switch(dataItem.categoryName) {
                case 'Processor':
                  break;
                case 'Memory':
                  $scope.currentRamNumber = dataItem.value;
                  break;
                case 'Network In':
                  break;
                case 'Network Out':
                  break;
                case 'Disk Read Bytes/Sec':
                  break;
                case 'Disk Write Bytes/Sec':
                  break;
                default:
                  //default code block
                  break;           
              }
            });     
          });
        }
      ]);</pre>
      <p>更改Hub類后,Visual Studio將報錯,您需要添加一個性能模型(由于Json.NET,它在服務(wù)器推送時會自動轉(zhuǎn)換為JSON):</p><pre class="brush:php;toolbar:false"><code>root
          app     (Angular應(yīng)用程序特定的JavaScript)
          Content (CSS等)
          Scripts (引用的JavaScript等)
          ...
          index.html</code></pre>
      <p>JsonProperty元數(shù)據(jù)只是告訴Json.NET在為此模型轉(zhuǎn)換為JSON時自動將屬性名稱轉(zhuǎn)換為小寫。JavaScript喜歡小寫。</p>
      <p>讓我們添加一個PerformanceEngine類,它將通過SignalR將真實性能數(shù)據(jù)推送到任何偵聽的客戶端。該引擎通過異步后臺線程通過SignalR向任何偵聽的客戶端發(fā)送這些消息。</p>
      <p>由于其長度,您可以在我們的GitHub存儲庫中找到代碼。</p>
      <p>此代碼基本上在每次while迭代中將一系列性能指標推送到任何已訂閱的客戶端。這些性能指標被注入到構(gòu)造函數(shù)中。從服務(wù)器推送的速度在構(gòu)造函數(shù)參數(shù)pollIntervalMillis上設(shè)置。</p>
      <p>請注意,如果您使用OWIN作為自托管來托管SignalR,這將運行良好,如果您使用Web工作線程,它也應(yīng)該運行良好。</p>
      <p>最后要做的事情當然是在服務(wù)的OnStart()或Startup類中的某個地方啟動后臺線程。</p>
      <pre class='brush:php;toolbar:false;'><!DOCTYPE html>
      <html>
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>AngularJS - SignalR - ServiceDashboard</title>
        <link rel="stylesheet" href="Content/bootstrap.min.css" />
        <link rel="stylesheet" href="Content/epoch.min.css" />
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
        <??>
        <??>
        <??>
        <??>
      
      </head>
      <body ng-app="angularServiceDashboard">
      
      </body>
      </html></pre>
      <p>啟動后臺線程的兩行代碼(正如您猜到的那樣)是我們實例化PerformanceEngine和調(diào)用OnPerformanceMonitor()的地方。</p>
      <p>現(xiàn)在,我知道您可能認為我正在隨機化來自服務(wù)器的數(shù)據(jù),這是事實。但是要推送真實指標,只需使用System.Diagnostics庫和Windows提供的PerformanceCounter即可。我試圖保持簡單,但這就是代碼的樣子:</p>
      <pre class='brush:php;toolbar:false;'>'use strict';
      
      var app = angular.module('angularServiceDashboard', ['ng.epoch','n3-pie-chart']);
      app.value('backendServerUrl', 'http://sitepointsignal.cloudapp.net/');</pre>
      <h2 id="結(jié)論">結(jié)論</h2>
      <p>我們已經(jīng)了解了如何通過Angular使用SignalR數(shù)據(jù),并且我們已經(jīng)將該數(shù)據(jù)連接到Angular端的實時圖表框架。</p>
      <p>此處顯示客戶端最終版本的演示,您可以從此處獲取代碼。</p>
      <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174002672199955.jpg" class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS ">此處顯示服務(wù)器最終版本的演示,您可以從此處獲取代碼。</p>
      <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/174002672259072.jpg" class="lazy" alt="Build a Real-time SignalR Dashboard with AngularJS ">我希望您喜歡這個演練。如果您嘗試過類似的方法,請在評論中告訴我們!</p>
      <h2 id="使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答-FAQ">使用AngularJS構(gòu)建實時SignalR監(jiān)控面板的常見問題解答 (FAQ)</h2>
      <h3 id="如何在AngularJS中設(shè)置SignalR">如何在AngularJS中設(shè)置SignalR?</h3>
      <p>在AngularJS中設(shè)置SignalR涉及幾個步驟。首先,您需要使用NuGet或npm安裝SignalR庫。安裝后,您可以在服務(wù)器上創(chuàng)建一個新的SignalR中心。此中心將負責發(fā)送和接收消息。在客戶端,您需要引用SignalR JavaScript庫并創(chuàng)建到您的中心的連接。然后,您可以啟動連接并定義處理傳入消息的函數(shù)。</p>
      <h3 id="如何處理SignalR中的連接錯誤">如何處理SignalR中的連接錯誤?</h3>
      <p>SignalR提供了一種處理連接錯誤的內(nèi)置機制。您可以使用中心連接上的.error()函數(shù)來定義一個回調(diào)函數(shù),該函數(shù)將在發(fā)生錯誤時調(diào)用。此回調(diào)函數(shù)可以向用戶顯示錯誤消息或嘗試重新連接到中心。</p>
      <h3 id="我可以將SignalR與其他JavaScript框架一起使用嗎">我可以將SignalR與其他JavaScript框架一起使用嗎?</h3>
      <p>是的,SignalR可以與任何支持AJAX和WebSockets的JavaScript框架一起使用。這包括流行的框架,如React、Vue.js和Angular。您只需要將SignalR JavaScript庫包含在您的項目中并像在任何其他JavaScript應(yīng)用程序中一樣創(chuàng)建一個中心連接即可。</p>
      <h3 id="如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端">如何使用SignalR將消息從服務(wù)器發(fā)送到客戶端?</h3>
      <p>要將消息從服務(wù)器發(fā)送到客戶端,您可以使用中心的Clients屬性。此屬性提供方法,用于將消息發(fā)送到所有連接的客戶端、特定客戶端或客戶端組。您可以從服務(wù)器代碼的任何部分調(diào)用這些方法,以將實時更新發(fā)送到您的客戶端。</p>
      <h3 id="如何保護我的SignalR應(yīng)用程序">如何保護我的SignalR應(yīng)用程序?</h3>
      <p>SignalR提供了幾個保護應(yīng)用程序的選項。您可以使用[Authorize]屬性來限制對您的中心和中心方法的訪問。您還可以使用Global.asax文件中的MapHubs()方法為您的中心指定自定義授權(quán)器。此外,您可以使用SSL來加密SignalR流量并防止竊聽。</p>
      <h3 id="如何處理SignalR中的斷開連接">如何處理SignalR中的斷開連接?</h3>
      <p>SignalR會自動處理斷開連接并嘗試重新連接。但是,您也可以使用中心連接上的.disconnected()函數(shù)手動處理斷開連接。此函數(shù)允許您定義一個回調(diào)函數(shù),該函數(shù)將在連接丟失時調(diào)用。</p>
      <h3 id="我可以在非-NET服務(wù)器上使用SignalR嗎">我可以在非.NET服務(wù)器上使用SignalR嗎?</h3>
      <p>SignalR是一個.NET庫,旨在與.NET服務(wù)器一起使用。但是,可以通過使用兼容的WebSocket庫在非.NET服務(wù)器上使用SignalR。您需要在服務(wù)器上實現(xiàn)SignalR協(xié)議并自行處理連接和消息傳遞邏輯。</p>
      <h3 id="如何測試我的SignalR應(yīng)用程序">如何測試我的SignalR應(yīng)用程序?</h3>
      <p>您可以使用Postman或Fiddler等工具向您的中心發(fā)送HTTP請求并驗證響應(yīng)來測試您的SignalR應(yīng)用程序。您還可以為您的中心方法和客戶端函數(shù)編寫單元測試。</p>
      <h3 id="我可以在移動應(yīng)用程序中使用SignalR嗎">我可以在移動應(yīng)用程序中使用SignalR嗎?</h3>
      <p>是的,您可以在移動應(yīng)用程序中使用SignalR。SignalR JavaScript庫可以在使用Cordova或Ionic構(gòu)建的混合移動應(yīng)用程序中使用。對于原生移動應(yīng)用程序,iOS和Android都提供了SignalR客戶端。</p>
      <h3 id="如何擴展我的SignalR應(yīng)用程序">如何擴展我的SignalR應(yīng)用程序?</h3>
      <p>SignalR提供了幾個擴展應(yīng)用程序的選項。您可以使用Azure SignalR服務(wù),這是一個完全托管的服務(wù),它為您處理所有SignalR連接。您還可以使用后端,這是一個軟件層,用于在多個服務(wù)器之間分發(fā)消息。</p><p>以上是用AngularJS構(gòu)建實時信號儀表板的詳細內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!</p>
      
      
      						</div>
      					</div>
      					<div   id="377j5v51b"   class="wzconShengming_sp">
      						<div   id="377j5v51b"   class="bzsmdiv_sp">本站聲明</div>
      						<div>本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔相應(yīng)法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn</div>
      					</div>
      				</div>
      
      				<ins class="adsbygoogle"
           style="display:block"
           data-ad-format="autorelaxed"
           data-ad-client="ca-pub-5902227090019525"
           data-ad-slot="2507867629"></ins>
      
      
      
      				<div   id="377j5v51b"   class="AI_ToolDetails_main4sR">
      
      
      				<ins class="adsbygoogle"
              style="display:block"
              data-ad-client="ca-pub-5902227090019525"
              data-ad-slot="3653428331"
              data-ad-format="auto"
              data-full-width-responsive="true"></ins>
          
      
      
      					<!-- <div   id="377j5v51b"   class="phpgenera_Details_mainR4">
      						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
      							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
      								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									src="/static/imghw/hotarticle2.png" alt="" />
      								<h2>熱門文章</h2>
      							</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>2 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>2 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796822997.html" title="峰:如何復(fù)興球員" class="phpgenera_Details_mainR4_bottom_title">峰:如何復(fù)興球員</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>4 周前</span>
      										<span>By DDD</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796832397.html" title="Grass Wonder Build Guide |烏瑪媽媽漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |烏瑪媽媽漂亮的德比</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>1 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796823726.html" title="峰如何表現(xiàn)" class="phpgenera_Details_mainR4_bottom_title">峰如何表現(xiàn)</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>3 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      														</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
      								<a href="http://www.miracleart.cn/zh/article.html">顯示更多</a>
      							</div>
      						</div>
      					</div> -->
      
      
      											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
      							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
      								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/hottools2.png" alt="" />
      									<h2>熱AI工具</h2>
      								</div>
      								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title">
      													<h3>Undress AI Tool</h3>
      												</a>
      												<p>免費脫衣服圖片</p>
      											</div>
      										</div>
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title">
      													<h3>Undresser.AI Undress</h3>
      												</a>
      												<p>人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片</p>
      											</div>
      										</div>
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title">
      													<h3>AI Clothes Remover</h3>
      												</a>
      												<p>用于從照片中去除衣服的在線人工智能工具。</p>
      											</div>
      										</div>
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title">
      													<h3>Clothoff.io</h3>
      												</a>
      												<p>AI脫衣機</p>
      											</div>
      										</div>
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title">
      													<h3>Video Face Swap</h3>
      												</a>
      												<p>使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!</p>
      											</div>
      										</div>
      																</div>
      								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
      									<a href="http://www.miracleart.cn/zh/ai">顯示更多</a>
      								</div>
      							</div>
      						</div>
      					
      
      
      					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
      						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
      							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
      								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									src="/static/imghw/hotarticle2.png" alt="" />
      								<h2>熱門文章</h2>
      							</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796828723.html" title="Agnes Tachyon Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Agnes Tachyon Build Guide |漂亮的德比志</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>2 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796827210.html" title="Oguri Cap Build Guide |漂亮的德比志" class="phpgenera_Details_mainR4_bottom_title">Oguri Cap Build Guide |漂亮的德比志</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>2 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796822997.html" title="峰:如何復(fù)興球員" class="phpgenera_Details_mainR4_bottom_title">峰:如何復(fù)興球員</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>4 周前</span>
      										<span>By DDD</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796832397.html" title="Grass Wonder Build Guide |烏瑪媽媽漂亮的德比" class="phpgenera_Details_mainR4_bottom_title">Grass Wonder Build Guide |烏瑪媽媽漂亮的德比</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>1 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/1796823726.html" title="峰如何表現(xiàn)" class="phpgenera_Details_mainR4_bottom_title">峰如何表現(xiàn)</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<span>3 周前</span>
      										<span>By Jack chen</span>
      									</div>
      								</div>
      														</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
      								<a href="http://www.miracleart.cn/zh/article.html">顯示更多</a>
      							</div>
      						</div>
      					</div>
      
      
      											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
      							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
      								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/hottools2.png" alt="" />
      									<h2>熱工具</h2>
      								</div>
      								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
      																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="記事本++7.3.1" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/toolset/development-tools/92" title="記事本++7.3.1" class="phpmain_tab2_mids_title">
      													<h3>記事本++7.3.1</h3>
      												</a>
      												<p>好用且免費的代碼編輯器</p>
      											</div>
      										</div>
      																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3漢化版" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/toolset/development-tools/93" title="SublimeText3漢化版" class="phpmain_tab2_mids_title">
      													<h3>SublimeText3漢化版</h3>
      												</a>
      												<p>中文版,非常好用</p>
      											</div>
      										</div>
      																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="禪工作室 13.0.1" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/toolset/development-tools/121" title="禪工作室 13.0.1" class="phpmain_tab2_mids_title">
      													<h3>禪工作室 13.0.1</h3>
      												</a>
      												<p>功能強大的PHP集成開發(fā)環(huán)境</p>
      											</div>
      										</div>
      																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title">
      													<h3>Dreamweaver CS6</h3>
      												</a>
      												<p>視覺化網(wǎng)頁開發(fā)工具</p>
      											</div>
      										</div>
      																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
      											<a href="http://www.miracleart.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_top_img">
      												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 Mac版" />
      											</a>
      											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
      												<a href="http://www.miracleart.cn/zh/toolset/development-tools/500" title="SublimeText3 Mac版" class="phpmain_tab2_mids_title">
      													<h3>SublimeText3 Mac版</h3>
      												</a>
      												<p>神級代碼編輯軟件(SublimeText3)</p>
      											</div>
      										</div>
      																	</div>
      								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
      									<a href="http://www.miracleart.cn/zh/ai">顯示更多</a>
      								</div>
      							</div>
      						</div>
      										
      
      					
      					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
      						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
      							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
      								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      									src="/static/imghw/hotarticle2.png" alt="" />
      								<h2>熱門話題</h2>
      							</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/gmailyxdlrkzn" title="gmail郵箱登陸入口在哪里" class="phpgenera_Details_mainR4_bottom_title">gmail郵箱登陸入口在哪里</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/eyess.png" alt="" />
      											<span>8644</span>
      										</div>
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/tiezi.png" alt="" />
      											<span>17</span>
      										</div>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/java-tutorial" title="Java教程" class="phpgenera_Details_mainR4_bottom_title">Java教程</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/eyess.png" alt="" />
      											<span>1787</span>
      										</div>
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/tiezi.png" alt="" />
      											<span>16</span>
      										</div>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/cakephp-tutor" title="CakePHP 教程" class="phpgenera_Details_mainR4_bottom_title">CakePHP 教程</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/eyess.png" alt="" />
      											<span>1730</span>
      										</div>
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/tiezi.png" alt="" />
      											<span>56</span>
      										</div>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/laravel-tutori" title="Laravel 教程" class="phpgenera_Details_mainR4_bottom_title">Laravel 教程</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/eyess.png" alt="" />
      											<span>1582</span>
      										</div>
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/tiezi.png" alt="" />
      											<span>29</span>
      										</div>
      									</div>
      								</div>
      															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
      									<a href="http://www.miracleart.cn/zh/faq/php-tutorial" title="PHP教程" class="phpgenera_Details_mainR4_bottom_title">PHP教程</a>
      									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/eyess.png" alt="" />
      											<span>1451</span>
      										</div>
      										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
      											<img src="/static/imghw/tiezi.png" alt="" />
      											<span>31</span>
      										</div>
      									</div>
      								</div>
      														</div>
      							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
      								<a href="http://www.miracleart.cn/zh/faq/zt">顯示更多</a>
      							</div>
      						</div>
      					</div>
      				</div>
      			</div>
      							<div   id="377j5v51b"   class="Article_Details_main2">
      					<div   id="377j5v51b"   class="phpgenera_Details_mainL4">
      						<div   id="377j5v51b"   class="phpmain1_2_top">
      							<a href="javascript:void(0);" class="phpmain1_2_top_title">Related knowledge<img
      									src="/static/imghw/index2_title2.png" alt="" /></a>
      						</div>
      						<div   id="377j5v51b"   class="phpgenera_Details_mainL4_info">
      
      													<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796822063.html" title="Java vs. JavaScript:清除混亂" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175035046165294.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Java vs. JavaScript:清除混亂" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796822063.html" title="Java vs. JavaScript:清除混亂" class="phphistorical_Version2_mids_title">Java vs. JavaScript:清除混亂</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 20, 2025 am	 12:27 AM</span>
      								<p class="Articlelist_txts_p">Java和JavaScript是不同的編程語言,各自適用于不同的應(yīng)用場景。Java用于大型企業(yè)和移動應(yīng)用開發(fā),而JavaScript主要用于網(wǎng)頁開發(fā)。</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796827639.html" title="如何在JS中與日期和時間合作?" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175130445135407.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何在JS中與日期和時間合作?" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796827639.html" title="如何在JS中與日期和時間合作?" class="phphistorical_Version2_mids_title">如何在JS中與日期和時間合作?</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 01, 2025 am	 01:27 AM</span>
      								<p class="Articlelist_txts_p">JavaScript中的日期和時間處理需注意以下幾點:1.創(chuàng)建Date對象有多種方式,推薦使用ISO格式字符串以保證兼容性;2.獲取和設(shè)置時間信息可用get和set方法,注意月份從0開始;3.手動格式化日期需拼接字符串,也可使用第三方庫;4.處理時區(qū)問題建議使用支持時區(qū)的庫,如Luxon。掌握這些要點能有效避免常見錯誤。</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796828200.html" title="為什么要將標簽放在的底部?" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175139053194540.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="為什么要將標簽放在的底部?" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796828200.html" title="為什么要將標簽放在的底部?" class="phphistorical_Version2_mids_title">為什么要將標簽放在的底部?</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 02, 2025 am	 01:22 AM</span>
      								<p class="Articlelist_txts_p">PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796822037.html" title="JavaScript與Java:開發(fā)人員的全面比較" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175035006093854.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="JavaScript與Java:開發(fā)人員的全面比較" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796822037.html" title="JavaScript與Java:開發(fā)人員的全面比較" class="phphistorical_Version2_mids_title">JavaScript與Java:開發(fā)人員的全面比較</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 20, 2025 am	 12:21 AM</span>
      								<p class="Articlelist_txts_p">JavaScriptIspreferredforredforwebdevelverment,而Javaisbetterforlarge-ScalebackendsystystemsandSandAndRoidApps.1)JavascriptexcelcelsincreatingInteractiveWebexperienceswebexperienceswithitswithitsdynamicnnamicnnamicnnamicnnamicnemicnemicnemicnemicnemicnemicnemicnemicnddommanipulation.2)</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796828191.html" title="什么是在DOM中冒泡和捕獲的事件?" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175139034116786.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="什么是在DOM中冒泡和捕獲的事件?" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796828191.html" title="什么是在DOM中冒泡和捕獲的事件?" class="phphistorical_Version2_mids_title">什么是在DOM中冒泡和捕獲的事件?</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 02, 2025 am	 01:19 AM</span>
      								<p class="Articlelist_txts_p">事件捕獲和冒泡是DOM中事件傳播的兩個階段,捕獲是從頂層向下到目標元素,冒泡是從目標元素向上傳播到頂層。1.事件捕獲通過addEventListener的useCapture參數(shù)設(shè)為true實現(xiàn);2.事件冒泡是默認行為,useCapture設(shè)為false或省略;3.可使用event.stopPropagation()阻止事件傳播;4.冒泡支持事件委托,提高動態(tài)內(nèi)容處理效率;5.捕獲可用于提前攔截事件,如日志記錄或錯誤處理。了解這兩個階段有助于精確控制JavaScript響應(yīng)用戶操作的時機和方式。</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796822137.html" title="JavaScript:探索用于高效編碼的數(shù)據(jù)類型" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175035157160537.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="JavaScript:探索用于高效編碼的數(shù)據(jù)類型" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796822137.html" title="JavaScript:探索用于高效編碼的數(shù)據(jù)類型" class="phphistorical_Version2_mids_title">JavaScript:探索用于高效編碼的數(shù)據(jù)類型</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 20, 2025 am	 12:46 AM</span>
      								<p class="Articlelist_txts_p">javascripthassevenfundaMentalDatatypes:數(shù)字,弦,布爾值,未定義,null,object和symbol.1)numberSeadUble-eaduble-ecisionFormat,forwidevaluerangesbutbecautious.2)</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796824597.html" title="如何減少JavaScript應(yīng)用程序的有效載荷大小?" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175087047055234.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="如何減少JavaScript應(yīng)用程序的有效載荷大???" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796824597.html" title="如何減少JavaScript應(yīng)用程序的有效載荷大???" class="phphistorical_Version2_mids_title">如何減少JavaScript應(yīng)用程序的有效載荷大小?</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jun 26, 2025 am	 12:54 AM</span>
      								<p class="Articlelist_txts_p">如果JavaScript應(yīng)用加載慢、性能差,問題往往出在payload太大,解決方法包括:1.使用代碼拆分(CodeSplitting),通過React.lazy()或構(gòu)建工具將大bundle拆分為多個小文件,按需加載以減少首次下載量;2.移除未使用的代碼(TreeShaking),利用ES6模塊機制清除“死代碼”,確保引入的庫支持該特性;3.壓縮和合并資源文件,啟用Gzip/Brotli和Terser壓縮JS,合理合并文件并優(yōu)化靜態(tài)資源;4.替換重型依賴,選用輕量級庫如day.js、fetch</p>
      							</div>
      														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
      								<a href="http://www.miracleart.cn/zh/faq/1796828216.html" title="JavaScript模塊上的確定JS綜述:ES模塊與COMPORJS" class="phphistorical_Version2_mids_img">
      									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
      										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175139088179400.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="JavaScript模塊上的確定JS綜述:ES模塊與COMPORJS" />
      								</a>
      								<a href="http://www.miracleart.cn/zh/faq/1796828216.html" title="JavaScript模塊上的確定JS綜述:ES模塊與COMPORJS" class="phphistorical_Version2_mids_title">JavaScript模塊上的確定JS綜述:ES模塊與COMPORJS</a>
      								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 02, 2025 am	 01:28 AM</span>
      								<p class="Articlelist_txts_p">ES模塊和CommonJS的主要區(qū)別在于加載方式和使用場景。1.CommonJS是同步加載,適用于Node.js服務(wù)器端環(huán)境;2.ES模塊是異步加載,適用于瀏覽器等網(wǎng)絡(luò)環(huán)境;3.語法上,ES模塊使用import/export,且必須位于頂層作用域,而CommonJS使用require/module.exports,可在運行時動態(tài)調(diào)用;4.CommonJS廣泛用于舊版Node.js及依賴它的庫如Express,ES模塊則適用于現(xiàn)代前端框架和Node.jsv14 ;5.雖然可混合使用,但容易引發(fā)問題</p>
      							</div>
      													</div>
      
      													<a href="http://www.miracleart.cn/zh/web-designer.html" class="phpgenera_Details_mainL4_botton">
      								<span>See all articles</span>
      								<img src="/static/imghw/down_right.png" alt="" />
      							</a>
      											</div>
      				</div>
      					</div>
      	</main>
      	<footer>
          <div   id="377j5v51b"   class="footer">
              <div   id="377j5v51b"   class="footertop">
                  <img src="/static/imghw/logo.png" alt="">
                  <p>公益在線PHP培訓(xùn),幫助PHP學(xué)習者快速成長!</p>
              </div>
              <div   id="377j5v51b"   class="footermid">
                  <a href="http://www.miracleart.cn/zh/about/us.html">關(guān)于我們</a>
                  <a href="http://www.miracleart.cn/zh/about/disclaimer.html">免責聲明</a>
                  <a href="http://www.miracleart.cn/zh/update/article_0_1.html">Sitemap</a>
              </div>
              <div   id="377j5v51b"   class="footerbottom">
                  <p>
                      ? php.cn All rights reserved
                  </p>
              </div>
          </div>
      </footer>
      
      <input type="hidden" id="verifycode" value="/captcha.html">
      
      
      
      
      		<link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' />
      	
      	
      	
      	
      	
      
      	
      	
      
      
      
      
      
      
      <footer>
      <div class="friendship-link">
      <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p>
      <a href="http://www.miracleart.cn/" title="国产av日韩一区二区三区精品">国产av日韩一区二区三区精品</a>
      
      <div class="friend-links">
      
      
      </div>
      </div>
      
      </footer>
      
      
      <script>
      (function(){
          var bp = document.createElement('script');
          var curProtocol = window.location.protocol.split(':')[0];
          if (curProtocol === 'https') {
              bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
          }
          else {
              bp.src = 'http://push.zhanzhang.baidu.com/push.js';
          }
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(bp, s);
      })();
      </script>
      </body><div id="hvlhm" class="pl_css_ganrao" style="display: none;"><delect id="hvlhm"><del id="hvlhm"></del></delect><th id="hvlhm"></th><legend id="hvlhm"></legend><center id="hvlhm"></center><video id="hvlhm"><ul id="hvlhm"><u id="hvlhm"><form id="hvlhm"></form></u></ul></video><ol id="hvlhm"><strike id="hvlhm"><wbr id="hvlhm"></wbr></strike></ol><form id="hvlhm"></form><acronym id="hvlhm"></acronym><thead id="hvlhm"><meter id="hvlhm"></meter></thead><track id="hvlhm"></track><sub id="hvlhm"><dfn id="hvlhm"><mark id="hvlhm"></mark></dfn></sub><pre id="hvlhm"></pre><tr id="hvlhm"></tr><th id="hvlhm"></th><dfn id="hvlhm"></dfn><optgroup id="hvlhm"></optgroup><address id="hvlhm"></address><legend id="hvlhm"><rt id="hvlhm"></rt></legend><fieldset id="hvlhm"></fieldset><rt id="hvlhm"></rt><small id="hvlhm"></small><td id="hvlhm"><dl id="hvlhm"></dl></td><ruby id="hvlhm"></ruby><acronym id="hvlhm"></acronym><menuitem id="hvlhm"></menuitem><tbody id="hvlhm"><optgroup id="hvlhm"><var id="hvlhm"><strong id="hvlhm"></strong></var></optgroup></tbody><p id="hvlhm"></p><p id="hvlhm"><td id="hvlhm"><form id="hvlhm"><address id="hvlhm"></address></form></td></p><strike id="hvlhm"><wbr id="hvlhm"><address id="hvlhm"><sub id="hvlhm"></sub></address></wbr></strike><nobr id="hvlhm"><small id="hvlhm"></small></nobr><strong id="hvlhm"></strong><acronym id="hvlhm"></acronym><small id="hvlhm"><style id="hvlhm"><optgroup id="hvlhm"><label id="hvlhm"></label></optgroup></style></small><style id="hvlhm"></style><delect id="hvlhm"><tt id="hvlhm"><b id="hvlhm"><optgroup id="hvlhm"></optgroup></b></tt></delect><center id="hvlhm"><dd id="hvlhm"><font id="hvlhm"><menuitem id="hvlhm"></menuitem></font></dd></center><del id="hvlhm"></del><acronym id="hvlhm"><pre id="hvlhm"><tbody id="hvlhm"><tr id="hvlhm"></tr></tbody></pre></acronym><small id="hvlhm"></small><menuitem id="hvlhm"></menuitem><rp id="hvlhm"><small id="hvlhm"></small></rp><li id="hvlhm"><optgroup id="hvlhm"><strong id="hvlhm"><menu id="hvlhm"></menu></strong></optgroup></li><li id="hvlhm"></li><pre id="hvlhm"></pre><blockquote id="hvlhm"><samp id="hvlhm"><tr id="hvlhm"></tr></samp></blockquote><legend id="hvlhm"></legend><tr id="hvlhm"><menuitem id="hvlhm"><mark id="hvlhm"><kbd id="hvlhm"></kbd></mark></menuitem></tr><dfn id="hvlhm"><ol id="hvlhm"><strong id="hvlhm"><object id="hvlhm"></object></strong></ol></dfn><strike id="hvlhm"><center id="hvlhm"></center></strike><sub id="hvlhm"></sub><small id="hvlhm"><noframes id="hvlhm"></noframes></small><object id="hvlhm"></object><strike id="hvlhm"></strike><style id="hvlhm"></style><wbr id="hvlhm"></wbr><span id="hvlhm"><pre id="hvlhm"></pre></span><dfn id="hvlhm"></dfn><menuitem id="hvlhm"><delect id="hvlhm"></delect></menuitem><style id="hvlhm"><rt id="hvlhm"><source id="hvlhm"></source></rt></style><optgroup id="hvlhm"><th id="hvlhm"></th></optgroup><tt id="hvlhm"><ins id="hvlhm"></ins></tt><nav id="hvlhm"></nav><abbr id="hvlhm"></abbr><optgroup id="hvlhm"><noframes id="hvlhm"><nobr id="hvlhm"><input id="hvlhm"></input></nobr></noframes></optgroup><dd id="hvlhm"><pre id="hvlhm"><dfn id="hvlhm"></dfn></pre></dd><form id="hvlhm"><optgroup id="hvlhm"></optgroup></form><i id="hvlhm"></i><ul id="hvlhm"><kbd id="hvlhm"><dfn id="hvlhm"><u id="hvlhm"></u></dfn></kbd></ul><menuitem id="hvlhm"></menuitem><acronym id="hvlhm"></acronym><menuitem id="hvlhm"><mark id="hvlhm"></mark></menuitem><small id="hvlhm"></small><th id="hvlhm"></th><object id="hvlhm"><label id="hvlhm"><pre id="hvlhm"></pre></label></object><dl id="hvlhm"><strike id="hvlhm"><big id="hvlhm"></big></strike></dl><address id="hvlhm"><sub id="hvlhm"><progress id="hvlhm"></progress></sub></address><strike id="hvlhm"><rt id="hvlhm"><acronym id="hvlhm"></acronym></rt></strike><style id="hvlhm"></style><tt id="hvlhm"></tt><fieldset id="hvlhm"></fieldset><rp id="hvlhm"><small id="hvlhm"><dfn id="hvlhm"></dfn></small></rp><source id="hvlhm"></source><dl id="hvlhm"></dl><style id="hvlhm"></style><dfn id="hvlhm"><label id="hvlhm"><pre id="hvlhm"></pre></label></dfn><noframes id="hvlhm"><li id="hvlhm"></li></noframes><table id="hvlhm"></table><pre id="hvlhm"></pre><abbr id="hvlhm"><li id="hvlhm"></li></abbr><track id="hvlhm"><u id="hvlhm"><style id="hvlhm"></style></u></track><optgroup id="hvlhm"><th id="hvlhm"></th></optgroup><table id="hvlhm"><strong id="hvlhm"><s id="hvlhm"><fieldset id="hvlhm"></fieldset></s></strong></table><input id="hvlhm"><object id="hvlhm"></object></input><b id="hvlhm"></b><p id="hvlhm"><input id="hvlhm"></input></p><wbr id="hvlhm"></wbr><small id="hvlhm"><noframes id="hvlhm"></noframes></small><sup id="hvlhm"></sup><label id="hvlhm"></label></div>
      
      </html>