javascript - 如何导入子对象

标签 javascript

在插件中给出这些导出

// Imagine these inner functions are written somewhere
export const WindowFunctions={
   maximize: maximizeFunction,
   minimize: minimizeFunction
}

export const FileFunctions={
   open: openFileFunction,
   close: closeFileFunction
}

// Pretend there is 20 other exports here

export default{
   WindowFunctions,
   FileFunctions,
   // imagine those 20 other exports here too
}

当使用 require 时,你可以访问它们

const {maximize} = require('yourPlugin').WindowFunctions

如何使用 import 来实现这一点?

到目前为止,我一直在这样做

import {WindowFunctions} from 'yourPlugin'
const maximize = WindowFunctions.maximize

有没有更好的方法来导入这些?

谢谢

最佳答案

import {WindowFunctions: {maximize}} from 'yourPlugin'

ES2015 命名导入不会解构。导入后使用另一条语句进行解构。

关于javascript - 如何导入子对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59095224/

相关文章:

javascript - 将图像放置在元素上以表示它被选择

javascript - 仅在 Blade 模板中使用 JQuery 检查每行的复选框

Javascript 按位运算符 - 需要解释

javascript - TotalVowels 变量未更新

javascript - 如何检查脏标志

javascript - 如何在 chrome 控制台中查看标签 eol 空间?

javascript - 使用 Babel 编译具有依赖关系的 javascript

javascript - scrapy填写POST表单

javascript - 单击标记打开 map 旁边的图像

javascript SQLITE_BUSY : database is locked, sql:插入到 "users"