[英]How do you import a JSON file with VueJS / Typescript?
我刚刚创建了一个干净的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并尝试了以下文章中的所有内容:
https://github.com/chybie/ts-json
好的,我现在设法通过将其添加到tsconfig.json来使其在运行npm run serve
时起作用:
{
"compilerOptions": {
"resolveJsonModule": true
}
}
但是,VSCode中的错误似乎仍然存在。 有没有办法解决这个问题?
只需添加resolveJsonModule": true
你tsconfig.json
下compilerOptions
:
diff --git a/tsconfig.json b/tsconfig.json
index 499f5e2..a05dab1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,6 +6,7 @@
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
+ "resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.