ES6 模块化操作

// export 输出
// import 引入
 
两个不同的.js文件 temp.js/index.js
temp.js
 
var a = 'js'
var b = '技术'
var c = 'web'
export {a,b,c}
 
//as方法重命名
export {
  a as name,
  b as cname,
  c as skill
}
 
//也可传入函数
export function add(a, b) {
  return a + b
}
 
// 采用默认命名方式
var a = 'js'
export default {a}
 
index.js
import {a,b,c} from './temp'
console.log(a,b,c); // js 技术 web
 
// 自定义shy
import shy from './temp'
console.log(shy.a);

猜你喜欢

转载自www.cnblogs.com/sunyang-001/p/10860472.html