前端模块化的理解

主要是ES6模块化

一句话就是:把一段代码封装起来,便于重复使用

1、es5之前没有模块化,使用commonJs的规范,使用module.exports导出,用require+path引入

module.exports = {
      name:"冬冬的随笔",
      funA:function(){
         return `我是${this.name}`
      }
}
require('./example.js')

2、ES6之后的模块化分为导出(export)与导入(import)

/**
 * 去除字符串中的空格
 */
export function delAllSpace(val) {
  return val.replace(/s/g, '')
}
import {delAllspace} from "./example.js"

2.css(@import语法)、js
3.vue与react也都是使用组件的形式开发也相当于模块化
4.微信小程序中的组件也使用了模块化

搞了半天,我还以为我会呢
原文地址:https://www.cnblogs.com/dongdong1996/p/14415405.html