导出方式一: export + 声明语句
例:(假设这是一个js文件){
export const name:'yyy'
export const age:18
}
导出方式二:export {(声明标识)}
例:(假设这是一个js文件){
const name:'yyy'
const age:18
function foo(){}
export { //这里要注意有大括号并不表示是一个对象哦 这是他的语法,所以里面不要写键值对
name,
age,
foo
}
}
导入方式二:起别名
例:
import {name as yName,age as yAge,foo as yFoo} from './xxx.js'
导入方式三:将导出的所以内容放到一个通配符标识符 '*'中
例:
import * as yyy from './xxx.js'
使用案列:
console.log(yyy.name) //取xxx.js中的元素
yyy.foo() //运行xxx.js中的方法