javascript - 从“”导入 {sub} VS 从“”导入 M
问题描述
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
导出解构对象不起作用,为什么?
解决方案
以下行仅获取默认情况下在“holy-components”中导出的变量
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
推荐阅读
- sql - 日期范围之间的 PostgreSQL 查询,但仅在特定时间之间
- python - 如何对存储为 Python 列表中的 numpy 数组的数字运行 for 循环
- python - 用于大型处理的 Dynamodb Stream
- python - 使用 Flask 的动态表单?
- laravel - 在 Laravel Eloquent 中,我可以在没有数据透视表的情况下定义多对多关系吗?
- mysql - 为什么使用 IN 作为子查询的一部分的 where 子句在显式完成时会返回不同的行数?
- pytorch - 张量的 Pytorch 成对串联
- azure - 如何使用 Whitesource API 将 Whitesource Report 集成到 Azure Dashboards
- android - Flutter setState在设置父无状态小部件标志时执行但不重新渲染UI
- json - ReactTable - 错误:文本字符串必须在
零件