0


每日一个前端小知识之type=module

对于js的引用一般有两种,第一种<script src='路径'>,另一种就是用type=module的形式,以下为type=module的使用实例

index.js:

export const sayHello = () => {
    console.log("Hello")
}

example:

<!DOCTYPE html>
<html lang="en">
<body>
    <script type="module">
        import {sayHello} from "./index.js"
        sayHello()
    </script>
</body>
</html>

通过上例我们可以知道在script中添加type=module可以使用import关键词来引入js文件

标签: 前端

本文转载自: https://blog.csdn.net/m0_74924621/article/details/133564101
版权归原作者 别问我,我什么都不知道 所有, 如有侵权,请联系我们删除。

“每日一个前端小知识之type=module”的评论:

还没有评论