ES6规范导入导出
导出示例
const baseURL='http://geek.itheima.net'
const getSum =(numA,numB)=>numA+numB
const getArraySum =arr =>{
let sum = 0
arr.forEach(item => sum += item)
return sum
}
export default {
getArraySum,
getSum,
url:baseURL,
}
导入示例
Node
警告
Node默认采用commonjs解析,请在package.json并配置"type":"module"
//语法:import 变量名 form '模块标识'
import obj from'./01_export.js'
console.log(obj);
console.log(obj.getArraySum([1,2,3]));
浏览器
<script type="module">
import obj from 'test.js'
console.log(obj)
</script>
更新日志
版权所有
版权归属:passwordgloo