一、创建tools.js文件
export const example = () => {
console.log('456');
};
二、创建index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script type="module">
import { example } from "./tools.js"
example();
</script>
</body>
</html>
以上是es6引入外部js函数的方法,需要注意的是:
1、js函数使用了箭头函数
2、箭头函数需要export暴露函数,给其他地方调用