- 通过export将内容导出
function sum (num, num2) {
return num + num2;
}
let flag = true;
class Persion {
run(){
console.log("在奔跑");
Perpoledata(name, age) {
this.name = name;
this.age = age
}
}
}
export { flag, sum, Persion }
export let num1 = 1000;
export function sum(num1, num2) {
return num1 + num2;
}
export class Person {
run() {
console.log("在奔跑");
}
}
export default function (msg) {
console.log(msg)
}
- 通过import将导出引入
import {flag, sum} from './xxx.js';
console.log(flag, sum(20,50));
import {Person} from './xxx.js';
const p = new Person();
p.run()
import hello from './xxx.js';
hello('你好呀');
import *as aaa from './xxx.js';
console.log(aaa.sum)
console.log(aaa.Persion)
如果遇到问题,可以发表评论和我一起讨论噢,我看到后都会第一时间尽力解答的
|