所以现在我有两个外部jQuery文件,paginate.js和custom.js。我通过npm install安装了jQuery。我尝试通过向app.js添加一些代码来加载这两个文件。
import $ from "jquery"
import paginate from "./paginate";
import custom from "./custom";
但是在控制台中,当我将上面的代码添加到app.js时,它会触发Uncaught ReferenceError:jQuery没有定义..我确信我成功安装了jQuery,因为我可以用jQuery编写一些代码来测试...有关将这些外部jQuery文件添加到我的凤凰应用程序的任何建议吗?为什么说Jquery没有定义?
提前致谢。
答案 0 :(得分:0)
所以我通过在brunch-config.js
中添加“jquery”来修复它npm: {
enabled: true,
// Whitelist the npm deps to be pulled in as front-end assets.
// All other deps in package.json will be excluded from the bundle.
whitelist: ["phoenix", "phoenix_html", "jquery"]
} };
我在白名单中没有“jquery”。添加之后,我的jQuery就可以了!