什么是模块化? 将若干份小的js文件合并到一起小的js文件需要暴露内容总js文件需要引入模块 暴露方式: // module1.js // 第一种暴露方式 export let ok = 1; export let add = function (a, b) { return a + b; } // module2.js // 集中式暴露 let yes = 2; let getName = function () { return "ce" } export {yes, getName} // module3.js // 默认暴露 let add1 = function (a, b) { return a + b } class Ball { constructor() {} } export default { add1, Ball } 引入模块: //html页面加 <script type="module" src="./js/app.js "></script> //app.js import * as m1 from './module1.js' import m3 from './module3.js' console.log(m1, m3) import {getName} from './module2.js' console.log(getName()) import {default as ok} from './module3.js'; console.log(ok)