es6 在 class 中导入 class

es6 importing a class in a class

在index.js我有。

import  PageLoader from './pageLoader';
$(function() {
  const pageLoader = new PageLoader();
});

和pageloader.js

class PageLoader{
   constructor(){
    {
       this.customer = null;
       this.data = [];
       this.init();
    }  
   } 
    init() { }
 }
module.exports = PageLoader;

一切正常。但是如果我从页面加载器导入 class。

import  Customer from './customer';
class PageLoader{
   constructor(){
    {
       this.customer = null;
       this.data = [];
       this.init();
    }  
   } 
    init() { }
 }
module.exports = PageLoader;

和customer.js

class Customer{
    constructor(){
       this.data = [];
       this.init();
    } 
    init() { 

    }
 }
 module.exports = Customer;

我收到

WARNING in ./src/index.js 10:23-33 "export 'default' (imported as 'PageLoader') was not found in './pageLoader'

module.exports

语法来自Modules (which are largely used in NodeJs - the counterpart of it is require rather than import). If you want to use import, you need to use export clause, which is from es6 modules

export default PageLoader

你也可以做命名导出

export { PageLoader };

然后

import { PageLoader } from './pageLoader'; 

Further reading