2017-07-07 37 views
-2

我使用巴貝爾ES6類:爲什麼ES6 expport和進口是凌亂

export class Util{ 
    async stringy(str){ 
    return await str 
    } 
} 

然後我將其導入

import Util from '../lib/util' 

,但它是不確定的。

+4

您需要使用'出口default'或使用'進口{的Util}' – 4castle

+0

這不是在所有雜亂(雖然這有點主觀) - 這是因爲你使用它錯了...... – Li357

回答

0

作爲4castle說,你已經混合了出口/進口類型。它應該是:

// util.js 
 
export class Util{ 
 
    async stringy(str){ 
 
    return await str 
 
    } 
 
} 
 

 
// other.js 
 
import { Util } from '../lib/util'

// util.js 
 
export default class Util{ 
 
    async stringy(str){ 
 
    return await str 
 
    } 
 
} 
 

 
// other.js 
 
import Util from '../lib/util'