Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript es6在类中导入类_Javascript_Webpack_Ecmascript 6_Es6 Modules_Es6 Class - Fatal编程技术网

Javascript es6在类中导入类

Javascript es6在类中导入类,javascript,webpack,ecmascript-6,es6-modules,es6-class,Javascript,Webpack,Ecmascript 6,Es6 Modules,Es6 Class,在index.js中,我有 import PageLoader from './pageLoader'; $(function() { const pageLoader = new PageLoader(); }); 和pageloader.js class PageLoader{ constructor(){ { this.customer = null; this.data = []; this.init(); }

在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;
一切正常。但是如果我从页面加载器导入一个类

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;
我收到

./src/index.js 10:23-33“导出‘默认’(导入为默认)”中的警告 在“./PageLoader”中找不到“PageLoader”)

module.exports
语法是from(在NodeJs中大量使用,对应的是
require
而不是import)。如果要使用
import
,需要使用
export
子句,它是from

您还可以进行命名导出

export { PageLoader };
然后

import { PageLoader } from './pageLoader'; 

module.exports
语法是from(在NodeJs中大量使用,对应的是
require
而不是import)。如果要使用
import
,需要使用
export
子句,它是from

您还可以进行命名导出

export { PageLoader };
然后

import { PageLoader } from './pageLoader'; 

为什么要导入一个类而从不使用它?我使用它只是不想用额外的代码来混淆示例OK,但这只是一个警告-代码实际工作吗?不,它不工作。你混合了commonjs和es6模块。modules.export来自commonjs(nodejs),import来自es6模块(es6 js)为什么你要导入一个类而从不使用它?我使用它只是不想用额外的代码弄乱示例OK,但这只是一个警告-代码实际工作吗?不,它不工作。你混合了commonjs和es6模块。modules.export来自commonjs(nodejs),import来自es6模块(es6 js)