在JavaScript中导入具有子对象和数组的对象
我有一个主题对象,它有许多对象和数组作为值。也就是说,类似这样的事情:在JavaScript中导入具有子对象和数组的对象,javascript,ecmascript-6,javascript-import,Javascript,Ecmascript 6,Javascript Import,我有一个主题对象,它有许多对象和数组作为值。也就是说,类似这样的事情: export const theme = { colors: {...list of colors}, breakpoints: [...array of breakpoints], ... } import { theme } from '../../theme' const { colors, breakpoints: bp } = theme } 现在,假设我想访问另一个文档中的color对象和断点数组
export const theme = {
colors: {...list of colors},
breakpoints: [...array of breakpoints],
...
}
import { theme } from '../../theme'
const { colors, breakpoints: bp } = theme
}
现在,假设我想访问另一个文档中的color对象和断点数组。目前,我正在导入如下主题:
export const theme = {
colors: {...list of colors},
breakpoints: [...array of breakpoints],
...
}
import { theme } from '../../theme'
const { colors, breakpoints: bp } = theme
}
我正在使用breakpoints:bp
,以便在我的文件中将断点
别名为bp
我想知道的是,是否有可能在import语句中执行所有这些操作。即,不导入整个主题
对象,只导入颜色对象和断点数组。类似这样的内容(此代码不起作用,只是为了说明这个想法):
这可能吗?如果是,怎么做
谢谢。您可能应该更改导出主题的方式。您可以只导出主题的每个属性,只需删除const声明并导出对象即可
export {
colors: {...list of colors},
breakpoints: [...array of breakpoints],
...
}
然后使用import本身:
import { colors, breakpoints as bp } from '../../themes'
我认为很不幸,政府不支持这项建议 我找到了解释这个问题的线索