export default
- export default 向外暴露的成员,可以使用任意的变量来接收
- 在一个模块中,export default 只允许向外暴露1次
- 在一个模块中,可以同时使用 export default 和 export 向外暴露成员
导出:
var info = {
name: 'zs',
age: 20
}
export default info
接收:
aaa可以任意命名,可以在控制台输出info对象
import aaa, from './test.js'
console.log(aaa)
export var title = ‘**’
- 使用 export 向外暴露的成员,只能使用 { } 的形式来接收;
- export 可以向外暴露多个成员, 同时,如果某些成员,我们在 import 的时候,不需要,则可以 不在 {} 中定义
- 使用 export 导出的成员,必须严格按照导出时候的名称,来使用 {} 按需接收;
- 使用 export 导出的成员,如果就想换个名称来接收,可以使用 as 来起别名;
导出:
export var title = '呵呵呵'
export var content = '哈哈哈'
接收:
import { title as title123, content } from './test.js'
console.log(title123 + ' --- ' + content)
export
使用 import ** from ** 和 import ‘路径’ 还有 import {a, b} from ‘模块标识’ 导入其他模块
import m222, { title as title123, content } from './test.js'
console.log(aaa)
console.log(title123 + ' --- ' + content)