问题
I'm trying to get GitGraph working and producing a GitFlow-like graph for a document I'm putting together.
Here's my HTML file:
<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>
When I open this in a browser I just get an empty/blank page. In Chrome Dev console I see the following error:
Uncaught ReferenceError: GitGraph is not defined
at gitgraph.html:6
So for some reason its not pulling in GitGraph from the CDN. Can anybody spot where I'm going awry?
回答1:
Got it working with this:
<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:
This
<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.css"></script>
is loading the css file. You can validate it from the file extension.
It need to be
<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
来源:https://stackoverflow.com/questions/48106879/gitgraph-js-not-loading-from-cdn