0%

前端的javascript笔记

一、语法

1. import导入js文件

1.1. export和import

  • 使用export default直接导出
1
2
3
4
5
6
7
8
9
10
const testObj = {a: 1, b: 2};

function testFunc(a, b) {
...
}

export default {
testObj,
testFunc,
};

使用

1
2
3
4
<script type="module">
import data from '/path/to/xxx.js'
data.testFunc(data.testObj.a, data.testObj.b)
</script>