我正在将JavaScript与webpack4和babel7一起使用。我对使用import * from ''
和import * as '' from ''
感到困惑。
以下代码:
import tbc from `tbc`
tbc
实例将具有default
属性,我必须使用tbc.default.xxx
。根据我的理解,它应该等于import {default as lib } from 'lib';
。但是为什么它具有default
属性?
但是下面的代码将允许我使用tbc
中的所有属性,例如tbc.xxx
。
import * as tbc from `tbc`
我想知道何时应该使用import * from
。
答案 0 :(得分:1)
文件-nums.js
export let one = 1;
export let two = 2;
文件-index.js
import {one, two} from "./nums";
alert( `${one} and ${two}` ); // 1 and 2
文件-index.js 您可以一次将所有值作为对象导入*作为obj导入,例如:
import * as numbers from "./nums";
alert( `${numbers.one} and ${numbers.two}` ); // 1 and 2