我正在尝试使用颜色日历,并且我正在按照他们在演示和文档中看到的教程进行操作,如下所示:
// js/calendar.js import Calendar from '../node_modules/color-calendar'; import '../node_modules/color-calendar/dist/css/theme-glass.css'; let calA = new Calendar({ id: "#color-calendar", theme: "glass", // border: "5px solid black", weekdayType: "long-upper", monthDisplayType: "long", // headerColor: "yellow", // headerBackgroundColor: "black", calendarSize: "small", layoutModifiers: ["month-left-align"], eventsData: [ { id: 1, name: "French class", start: "2020-12-17T06:00:00", end: "2020-12-18T20:30:00" }, { id: 2, name: "Blockchain 101", start: "2020-12-20T10:00:00", end: "2020-12-20T11:30:00" }, { id: 3, name: "Cheese 101", start: "2020-12-01T10:00:00", end: "2020-12-02T11:30:00" }, { id: 4, name: "Cheese 101", start: "2020-12-01T10:00:00", end: "2020-12-02T11:30:00" } ], dateChanged: (currentDate, events) => { console.log("date change", currentDate, events); }, monthChanged: (currentDate, events) => { console.log("month change", currentDate, events); } });
和我的 HTML:
// dashboard.html ... <div class="col"> <div class="calendar-container"> <div id="color-calendar"></div> <div id="events-display"></div> </div> </div> ... <script type="module" src="js/calendar.js"></script>
我尝试使用 http-server 和 Live Server 扩展来检查它是否解决了问题,但问题仍然存在。
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/css". Strict MIME type checking is enforced for module scripts per HTML spec.
我在我的开发工具控制台上得到了这两个
有关其他信息,这是我的 package.json
{ "dependencies": { "color-calendar": "^1.0.7", "http-server": "^14.1.1" } }
我不知道该怎么办了...没有 Node.js,没有框架,只是使用 javascript、html 和 css。
Konrad 和 Stefino76 带来的解决方案奏效了。
我在我的项目上安装了 webpack 并将其配置为接受 .js 文件中的 js 和 css,现在日历可以正常工作了!
所有的功劳都应该归功于他们,但我认为我无法将他们的答案标记为已解决。