es6模块化

1、es6模块.js
/*
var es6模块={
    name:'oldDog' ,
    fun:function () {
        return 'fun'
    }
}
export default es6模块*/


export default {
    name:'oldDog' ,
    fun:function () {
        return 'fun'
    }
}

  


2、创建html 并调用js模块
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<script type="module" >
import es6模块 from '/es6模块.js'
alert(es6模块.name);
alert(es6模块.fun());
</script>
</body>
</html>

  3、启动服务器并访问

http://localhost:8082/es6模块化.html

posted on 2020-03-22 19:19  苹果园dog  阅读(229)  评论(0编辑  收藏  举报

导航