Vue从零开始总结33
ES6的模块化导出和导入,前提是在引入每一个js文件的时候,script里面加上type="module"
如:<script type="module">
导出:
第一种:定义变量,函数或者类的时候直接导出。
export let age=20;
export function sum(){
}
export class Person{
}
第二种:以一个对象的形式导出。
export {age,sum,Person}
第三种:唯一性,只能导出一个,并且可以更改命名
export default age
导入:
第一种:引入指定导出内容
import {age,sum,Person} from "./x.js"
第二种:引入默认内容,并更名
import Age from "./x.js"
第三种:引入全部导出内容,并起个新名字,之后通过这个名字来拿东西
import * as new form "./x.js"
new.age;
new.sum;
new.Person;