【问题标题】:GitGraph JS not loading from CDNGitGraph JS 未从 CDN 加载
【发布时间】:2018-01-08 23:43:45
【问题描述】:

我正在尝试让 GitGraph 工作并为我正在整理的文档生成类似 GitFlow 的图表。

这是我的 HTML 文件:

<html>
  <head>
    <title>GitFlow</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.css"></script>
    <script>
      var gitgraph = new GitGraph({
        template: "blackarrow",
        reverseArrow: false,
        orientation: "horizontal",
        mode: "compact"
      });
    </script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.css" />
  </head>
  <body>
    <canvas id="gitGraph"></canvas>
  </body>
</html>

当我在浏览器中打开它时,我只会得到一个空/空白页面。在 Chrome 开发控制台中,我看到以下错误:

Uncaught ReferenceError: GitGraph is not defined
at gitgraph.html:6

所以由于某种原因,它没有从 CDN 中提取 GitGraph。有人能看出我哪里出错了吗?

【问题讨论】:

    标签: javascript cdn


    【解决方案1】:

    解决了这个问题:

    <html>
      <head>
        <title>GitFlow</title>
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.css" />
      </head>
      <body>
        <canvas id="gitGraph"></canvas>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
        <script>
          var gitgraph = new GitGraph({
            template: "blackarrow",
            reverseArrow: false,
            orientation: "horizontal",
            mode: "compact"
          });
    
          gitgraph.branch().commit().commit();
        </script>
      </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      这个

      <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.css"></script>
      

      正在加载 css 文件。您可以通过文件扩展名对其进行验证。

      应该是

      <script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
      

      【讨论】:

      • 感谢@brk (+1),根据您的建议,我仍然得到一个空白/空白页面,现在控制台错误是“Uncaught TypeError: Cannot read property 'getContext' of undefined”...有什么想法吗?也许是 GitGraph 本身的错误?!
      猜你喜欢
      • 1970-01-01
      • 2022-11-04
      • 2013-01-23
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2018-08-28
      相关资源
      最近更新 更多