ES模块化导入导出
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<!-- 模块化类型 -->
<script src="test.js" type="module"></script>
<script src="vue.js" type="module"></script>
</body>
</html>
法一
const name = 'furong';
const age = 12;
export {
name,
age
}
// 必须要写上路径
import {
name,
age
} from './vue.js';
console.log('name ' + name);
法二
export const name = 'furong';
export const age = 12;
导出函数
const name = 'furong';
const age = 12;
function getName() {
return name;
}
export {
getName
}
// 必须要写上路径
import {
getName
} from './vue.js';
console.log('name ' + getName());
default导出
导出只能使用一次,导入名字随意指定
export default getName;
import printName from './vue.js';
import *
import * as vue from './vue.js';
console.log('name ' + vue.name);
console.log('age ' + vue.age);