Module import or export statement unexpected here

前端 未结 1 1041
刺人心
刺人心 2021-01-27 02:20

I have problem with importing JS scripts from code. I have a canvas game, and want to import my classes rather than define they in HTML. But when I run my code in E

相关标签:
1条回答
  • 2021-01-27 02:51

    Solved! The problem was in HTML script declaration:

    I used this code:

    <script src="base/init.js"></script>
    

    But I don't knew, that I need to specify type attribute, with code below import works excellent!

    <script src="base/init.js" type="module"></script>
    

    UPD: variables just are file-scoped, to use in another file export variables:

    var myVar = "string";
    export {myVar};
    

    and then in your file

    import {myVar} from "<file>";
    
    0 讨论(0)
提交回复
热议问题