现在遇到麻烦,不知道如何工作。 我想从特定目录导入所有 json。
import a from '../context/a.json'
import b from '../context/b.json'
import c from '../context/c.json'
↓
import {a, b, c} '../context/' // but like..This code doesn't work.
有什么办法可以解决吗?
最佳答案
您可以在 context
目录中创建一个 index.js
文件,该文件导出 a、b 和 c。
// context/index.js
export {default as a} from "./a.json"
export {default as b} from "./b.json"
export {default as c} from "./c.json"
然后当你需要导入它时,你可以这样做
// some other js file
import { a, b, c} from "../context/index/"
关于javascript - typescript /javascript : How to do it that import all json from specific dir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60359371/