我才刚刚开始学习React JS。所以我有这2个JS文件:
polyfill.js结构
export default (function(window){
...
var classy = {
...
}
...
})(window);
!window.addEventListener && window.Element && (function () {
...
---code---
...
})();
这是customnavbar.js
import { cs } from "./polyfill";
(function(){
...
function openNav(){
...
cs.classy.add(overlay, 'on-overlay');
...
}
...
})();
这是我的component.jsx
import "./customnavbar.js"
...
...
它不起作用,错误提示未定义cs。也许我对导出语法有误?
<script src="./polyfill.js">
<script src="./customnavbar.js">
^我希望它像纯HTML一样工作,但是我不知道该如何做。请帮忙!
答案 0 :(得分:0)
import "./customnavbar.js"
对于模块导入而言不是有效的语法。
将type
元素中的<script>
设置为"module"
<script src="./polyfill.js" type="module">
return
来自IIFE的classy
对象
“ script.js”
export default (() => { const classy = {fn() { return 1 }}; return classy })();
import
导出的`经典对象
“ polyfill.js”
import classy from "./script.js";
// do stuff