从“”导入{sub} VS从“”导入M

时间:2019-07-16 10:42:35

标签: javascript import

export default { HolyClickoutside, ... } // "holy-components"

当我从“神圣的组成部分”中导入所需的内容时

import HolyComponents from "holy-components"
const { HolyClickoutside } = HolyComponents

console.log(HolyClickoutside)    // {...}

还可以

import { HolyClickoutside } from "holy-components" 

console.log(HolyClickoutside)    // undefined

导出的变形对象不起作用,为什么?

1 个答案:

答案 0 :(得分:0)

下面一行仅获取默认情况下在“神圣组件”中导出的变量

import HolyComponents from "holy-components"; // get whatever is exported by default in HolyComponents.

下面的行仅查找名为HolyClickoutside的变量,该变量可以是“ holy-components”中许多命名的导出文件之一。由于不存在具有特定名称的此类变量,因此您将无法定义。

import { HolyClickoutside } from "holy-components" // get the variable exported from "holy-components" which has the exact name as HolyClickOutside.

下面的行在名为HolyComponents的对象中查找名为HolyClickOutside的键。如果默认情况下从“ holy-components”导出的变量具有该键,则可以引用该键。

const { HolyClickoutside } = HolyComponents