如何在 ECMAScript 6 中访问 JSON 文件?
以下不起作用:
import config from '../config.json'
如果我尝试导入 JavaScript 文件,这会很好。
最佳答案
在 TypeScript 或使用 Babel 中,您可以在代码中导入 json 文件。
// Babel
import * as data from './example.json';
const word = data.name;
console.log(word); // output 'testing'
引用: https://hackernoon.com/import-json-into-typescript-8d465beded79
https://stackoverflow.com/questions/34944099/
相关文章:
javascript - 如何使用 html 表单数据发送 JSON 对象
json - curl json 通过终端向 Rails 应用程序发布请求
python - json.load() 和 json.loads() 函数有什么区别
android - 将 ArrayList
javascript - 从AngularJS中的对象数组中通过id获取特定对象
javascript - 无法使用 "-"破折号访问 JSON 属性
c# - ASP.NET Core 返回带有状态码的 JSON