我正在使用带有以下代码的 Rails 5.1.4。我已确认material.js正在处理该文件并且material-components-web已下载并发现该模块。
为什么mdc调用时未定义window.mdc.autoInit()?
// app/javascript/packs/material.js
import 'material-components-web'
// app/views/layouts/application.html.eeb
<html>
<head>
<%= javascript_pack_tag 'material' %>
</head>
<body>
<script>window.mdc.autoInit();</script>
</body>
</html>
我努力了
- 分别进口
@material/auto-init。 - 将
autoInit调用放入 onload - 添加
console.dir(window)/console.dir(this)内部包文件。this不在window包文件中,并且导出未附加到this