在单个 Phoenix 模板中要求定义的 JavaScript 模块的标准方法是什么?
除了这个模板之外,我不希望在任何地方都需要该模块。
这是我正在使用的文件的片段。
网络/静态/js/trend_chart.js
let TrendChart = {
//... some JS module code here
}
网页/模板/布局/app.html.eex
这具有标准的应用程序加载/要求。
...
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
<script>require("web/static/js/app")</script>
...
网页/模板/页面/index.html.eex
<!-- what do i put in this template to require / load the TrendChart module code? -->
<!-- i don't want it required globally, so i don't want to put it in the app.html.eex file -->
更新#1
我真的在寻找一种@inner
在主布局中有两个块的方法。一个用于内容,一个用于在内容之后加载的附加 JavaScript 项。
类似于ASP.NET MVC 中的部分。(我知道我知道!)
所以app.html.eex
最终会是这样的:
...
@inner
...
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
<script>require("web/static/js/app")</script>
*something here to load page/template specific javascript*