【发布时间】:2019-06-25 21:11:17
【问题描述】:
我刚刚创建了一个干净的 VueJS 新项目,但无法加载 JSON 文件。
复制/发行
为了便于复制,我为我的问题创建了一个 Github 存储库: https://github.com/devedse/VueJSImportJsonFile
在 Home.vue 页面中,我试图让 Json 加载工作。 (https://github.com/devedse/VueJSImportJsonFile/blob/master/src/views/Home.vue)
当您在 VSCode 中打开此解决方案时,以下行显示错误:
import theJson from '@/assets/hi.json';
Can't find module '@/assets/hi.json'
我已经尝试过的
我已经搜索了所有的 stackoverflow 并尝试了以下帖子中的所有内容:
Importing json file in TypeScript
Typescript compiler error when importing json file
https://github.com/chybie/ts-json
编辑 1:
好的,我现在在运行 npm run serve 时设法让它工作,方法是将它添加到 tsconfig.json:
{
"compilerOptions": {
"resolveJsonModule": true
}
}
但是 VSCode 中的错误似乎仍然存在。有没有办法解决这个问题?
【问题讨论】:
标签: javascript typescript vue.js