一种方法是将 分配Proposal
给 object window.Proposal
。
你可以直接在里面设置application.js
如下:
// proposals.js
function openProposalMirror() {}
export { openProposalMirror }
// application.js
import * as Proposal from "./proposals.js"
window.Proposal = Proposal
// view
onclick="Proposal.openProposalMirror()"
您还可以重新导出Proposal
然后application.js
导入并将其分配给标签中的对象window.Proposal
(<script>
在视图中),如下所示:
// application.js
import * as Proposal from "./proposals.js"
export { Proposal };
// view
<%= javascript_importmap_tags %>
<script type="module">
import { Proposal } from "application"
window.Proposal = Proposal;
</script>