2016-08-12 47 views
2

當我嘗試加載日曆時,webpack編譯器似乎無法識別jQuery正在使用?我正在關注basic usage指南

我假設因爲完整的日曆已經綁定了jquery,我已經不需要調用它了。

在我app.js我通過

import fullCalendar from 'fullCalendar'; 
const calendar = document.getElementById('calendar'); 

$(calendar).fullCalendar(); 

調用fullCalendar我知道我做錯了什麼,我無法找到完整的日曆文檔中的任何導入方法。

+1

這可能是因爲你是在純javascript和jquery之間切換。你應該使用一個或另一個。嘗試使用$('#calendar')創建日曆 – Justin

+1

Justin是正確的,'getElementById'返回一個HTML DOM元素,而jQuery的'$(...)'返回一個jQuery對象 –

+1

@Justin感謝您的回覆。我切換到你的方法,我仍然導致相同的錯誤。 – Simon

回答

1

1)通過NPM安裝(npm install fullcalendar --save-dev

2)在webpack.config.js具有以下

module.exports = { 
    entry: [ 
     'fullcalendar', 
     ... 
    ] 
} 

3)在你的JavaScript

require("fullcalendar"); //maybe import works as well 
$calendar.fullCalendar(); 
相關問題