GitGraph JS没有从CDN加载

时间:2018-01-05 03:35:13

标签: javascript cdn

我试图让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。任何人都可以找到我出错的地方吗?

2 个答案:

答案 0 :(得分:3)

使用它:

<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>

答案 1 :(得分:0)

这个

<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>