lesson17.js
export let A=123;//导出语句用export
export function test() {
console.log('test');
}
export class Hello{
test(){
console.log('class');
}
}
index.js
// import {A,test,Hello} from './class/lesson17';
// console.log(A,test,Hello);
// import {A} from './class/lesson17';
//console.log(A);
import * as lesson from './class/lesson17';// *符号代表导入所有内容,lesson是起的别名
console.log(lesson.A,lesson.test);
以上方式不建议
建议以下方式
index.js
import Lesson17 from './class/lesson17';
console.log(Lesson17.A);
lesson17.js
let A=123;
let test=function(){
console.log('test');
}
class Hello{
test(){
console.log('class');
}
}
export default {
A,
test,
Hello
}
网友评论