javascript - 将多个变量合二为一
问题描述
在 TS 中,我有来自 class.ts 的Class1,来自helper.ts的一些函数,来自variables.ts的一些变量:
例如,variables.ts看起来像这样:
export const test1 = 'test1';
export const test2 = 0;
export const test3 = 'test3';
export const test4 = 'test4';
然后使用 Webpack,我给 api.ts 提供了构建模块的入口。
api.ts
export { Class1 } from './class1';
export { helper1, helper2 } from './helper';
export * from './variables';
像这样,在我的 web 应用程序中,在 JS 中,我从这个模块中导入我需要的东西。但是,不是像这样导入每个变量:
import { test1, test2, test3, test4 } from 'api';
我想知道是否可以导入这样的东西:
import { variables } from 'api';
test1 = variables.test1;
或类似的东西:
import { variables.test1, variables.test3} from 'api';
我应该在 TS 中改变什么来做到这一点?
解决方案
只需使用一个名为的包装器对象variables
:
export const variables = {
test1: 'test1',
test2: 0,
test3: 'test3',
test4: 'test4'
};
推荐阅读
- html - 制作响应式广告页面 html bootstrap
- mongodb - 如何根据动态值在 Apache NiFi 中查询 MongoDB?
- java - Azure java sdk 中长期存在的 Azure 和 Azure.Authenticated 客户端的保证是什么?
- vba - 如何从电子邮件中提取数据?
- javascript - What is the term to describe the keywords let, const and var?
- docker - kubernetes/docker 中的 jvm 内存不足的速度比独立的快
- python - 如何将字符串转换为布尔逻辑?
- python - 是否可以设置多列索引顺序?
- javascript - 如何无限期地做某事,直到满足条件,没有循环?
- php - $mysqli->escape_string - 可以在不指定确切字段名称的情况下使用吗