javascript - Correct syntax to import constants in ES6
问题描述
Given the following modules, how do I import the constants module and avoid having the default property included:
// constants.es6
export default {
foo: 'foo',
bar: 'bar'
}
// anotherModule.es6
import * as constants from './constants';
results in constants.default.foo
I can't seem to get the syntax correct to end up with constants.foo
解决方案
import constants from './constants'
console.log(constants.foo, constants.bar)
If you would like to import the constants directly from ./constants
constants.js:
export const foo = 'foo'
export const bar = 'bar'
anotherModule.js:
import {foo, bar} from './constants'
console.log(foo,bar)
推荐阅读
- swift - 按最后喜欢的时间和最近的两个喜欢的时间来构建 Firebase
- javascript - 如何使用 JS 使用随机答案自动填充 Google 表单
- css - 有没有办法制作无限/循环水平滚动CSS?
- azure - 如何为变量值强制使用特定模式
- algorithm - 将线重新排列为圆直径的算法
- google-apps-script - Google Scripts - 创建表单后找不到目标表
- javascript - gfs 在 server.js 上声明,我想检索 files.js 上的文件并且不能使用 gfs.files.find() 因为 gfs 在 server.js 上被清除
- ios - 对集合视图项进行排序
- java - 即使 @Qualifier 值在构造函数注入中不匹配,Bean 也会被注入
- xcode - Change color of image (icon) in tabItems in SwiftUI