在插件中给出这些导出
// 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/