export和之間的Typescript有什么區別default export。在所有教程中,我看到人們在寫export他們的課程,并且如果我default在導出之前未添加關鍵字,則無法編譯我的代碼。另外,我在官方打字稿文檔中找不到默認export關鍵字的任何痕跡。export class MyClass { collection = [1,2,3];}不編譯。但:export default class MyClass { collection = [1,2,3];}有。錯誤是: error TS1192: Module '"src/app/MyClass"' has no default export.
3 回答

Cats萌萌
TA貢獻1805條經驗 獲得超9個贊
這是簡單對象導出的示例。
var MyScreen = {
/* ... */
width : function (percent){
return window.innerWidth / 100 * percent
}
height : function (percent){
return window.innerHeight / 100 * percent
}
};
export default MyScreen
在主文件中(不需要和不需要創建新實例時使用),并且它不是全局的,只有在需要時才導入它:
import MyScreen from "./module/screen";
console.log( MyScreen.width(100) );
- 3 回答
- 0 關注
- 506 瀏覽
添加回答
舉報
0/150
提交
取消