Chrome 62 javascript模块
我导入这样的模块:Chrome 62 javascript模块,javascript,jquery,google-chrome,es6-modules,Javascript,Jquery,Google Chrome,Es6 Modules,我导入这样的模块: <script type="module"> import mod_test from '../classes/mod_test.js'; window.mod_test= mod_test; </script> 由于您没有CORS问题,我认为问题可能是在模块加载和模块导出函数调用之间的竞争条件下。当然,您可以尝试以下方法。在模块加载程序之前定义应用程序运行程序: <script> window.runTheApp
<script type="module">
import mod_test from '../classes/mod_test.js';
window.mod_test= mod_test;
</script>
由于您没有CORS问题,我认为问题可能是在模块加载和模块导出函数调用之间的竞争条件下。当然,您可以尝试以下方法。在模块加载程序之前定义应用程序运行程序:
<script>
window.runTheApp = function(mod_test) {
mod_test.test();
// ...
}
</script>
window.runTheApp=函数(mod_测试){
mod_test.test();
// ...
}
然后使用app runner调用加载您的模块:
<script type="module">
import mod_test from '../classes/mod_test.js';
window.runTheApp(mod_test);
</script>
从“../classes/mod_test.js”导入mod_测试;
运行应用程序(模块测试);
此外,这种方法也可能有用。对我来说,这让方法更加清晰:
<script type="module">
import('../classes/mod_test.js')
.then(function(module) {
console.log('module loaded');
window.runTheApp(module.default);
})
</script>
导入('../classes/mod_test.js')
.then(功能(模块){
console.log('module-loaded');
runTheApp(module.default);
})
由于您没有CORS问题,我认为问题可能是在模块加载和模块导出函数调用之间的竞争条件下。当然,您可以尝试以下方法。在模块加载程序之前定义应用程序运行程序:
<script>
window.runTheApp = function(mod_test) {
mod_test.test();
// ...
}
</script>
window.runTheApp=函数(mod_测试){
mod_test.test();
// ...
}
然后使用app runner调用加载您的模块:
<script type="module">
import mod_test from '../classes/mod_test.js';
window.runTheApp(mod_test);
</script>
从“../classes/mod_test.js”导入mod_测试;
运行应用程序(模块测试);
此外,这种方法也可能有用。对我来说,这让方法更加清晰:
<script type="module">
import('../classes/mod_test.js')
.then(function(module) {
console.log('module loaded');
window.runTheApp(module.default);
})
</script>
导入('../classes/mod_test.js')
.then(功能(模块){
console.log('module-loaded');
runTheApp(module.default);
})
你能不能也展示一下你的mod_test.js
?如何从中导出mod_test
?好的,您是否看到脚本在无法读取属性之后立即被CORS策略阻止了错误?不,我在日志中没有看到它…您是否也可以显示mod_test.js
?如何从中导出mod_test
?好的,您是否看到脚本在无法读取属性之后立即被CORS策略阻止了错误?不,我在日志中没有看到它…相同的错误,但我注意到如果使用Strg+F5或location重新加载脚本。重新加载(true)正常。HTML中的meta标记如果不创建缓存也不会起作用。…@crak我将日志添加到模块加载程序中,您是否在控制台中的“无法读取属性”错误之前看到“模块加载”消息?相同的错误,但我注意到如果使用Strg+F5或location.reload(true)重新加载,它会起作用。HTML中的meta标记如果不创建缓存也不会起作用。…@crak I将日志添加到模块加载器中,您是否在控制台中的“无法读取属性”错误之前看到“模块加载”消息?