我在下面的代码中使用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发布于 2017-11-28 11:40:12
为了使material-components-web与Rails一起工作,我做到了
// app/javascript/packs/material.js
import * as mdc from 'material-components-web'
// for accessing it as a window object
window.mdc = mdc然后我确保window.mdc.autoInit()在身体末端被召唤
https://stackoverflow.com/questions/47528242
复制相似问题