这有效
import config from './setup/config'
const {port} = config;
这使端口未定义
import config, {port} from './setup/config'
// config.port returns a number but port alone is undefined
这也是未定义的
import {port} from './setup/config'
const {port} = config;
是一个解构赋值。它port
从 中的对象“拉出”属性config
。
import {port} from './setup/config'
从模块导入命名导出 。port
./setup/config
您的模块可能没有命名的 export port
。作为默认导出导出的对象的属性不会神奇地成为命名导出!
通过阅读让自己更熟悉 ES6 模块
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句