ES6 import和export使用记录
在使用三大框架进行开发的时候,经常遇到公共文件封装的公共方法导出的问题。进行记录一下:
场景:
// a.js export function fnA1(){ // 方法体 } export function fnA2(){ // 方法体 } export function fnA3(){ // 方法体 } // b.js export function fnB1(){ // 方法体 } export function fnB2(){ // 方法体 } export function fnB3(){ // 方法体 } // 在index.js中导入并导出 方法一: import {A1, A2, A3} from './a'; import {B1, B2, B3} from './b'; export { A1, A2, A3, B1, B2, B3 } // 方法二: // 可以直接简化为 export * from './a'; export * from './b';