Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

vue.js - How to import json file in current vue default setup?

There is this answer but it is wrong as it references tsconfig.json which is non-existant in vue projects now.

How do you import a JSON file with VueJS / Typescript?

I suspect the configuration option

{
  "compilerOptions": {
    "resolveJsonModule": true
  }
}

should go somewhere. Where?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

tsconfig.json is used when you use TypeScript. If you used the Vue CLI to build your program, it should come with Webpack. With webpack => 2.0.0, json-loader comes by default, so you can load .json files directly with

import jsonObject from '/path/to/file.json';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...