根据 SO question Global javascript variable inside document.ready,我应该能够在 jQuery 的文档就绪函数中使用全局变量。当我的变量在模块中声明时,我该如何做同样的事情?
<script type="module">
import settings from './config/settings.js';
var DAPP_VERSION = settings.version;
</script>
<script type="text/javascript">
var OTHER = 4;
</script>
<script type="text/javascript">
$(document).ready(function() {
console.log(OTHER);
console.log(DAPP_VERSION);
});
</script>
以上给了我:
未捕获的 ReferenceError:未定义 DAPP_VERSION
config/setting.js
包含:
export default {
version: "1.1",
rounds: 3,
cars: 20,
lapLenght: "short"
}