rashidnk
rashidnk

Reputation: 4292

Vue JS Keep all imports in different file

Iam learning vuejs, i have hundreds of json file i want to load in to my Vue project , in my script, Simply i can do this loading all json files directly in main file as below

//Index.vue
<script>
import data1 from 'assets/json/data1.json';
import data2 from 'assets/json/data2.json';
...

above works fine, but now im planning to keep all imports into different file as below

//assets/imports.js
import data1 from 'assets/json/data1.json';
import data2 from 'assets/json/data2.json';

and refer imports.js as

//Index.vue
<script>
import alldata from 'assets/imports'

is it possible to do like this, in not good in webpack too

Upvotes: 0

Views: 154

Answers (1)

Antony
Antony

Reputation: 1273

As requested, posting this as an answer:

Yes you can, simply merge all of your data in an object or array in the imports.js, then export the resulting object/array as default export

Upvotes: 1

Related Questions