0

Greetings to the community! This is my first question on the StackOverflow.

I use vue.js-v2 and webpack. I need to have immutable data available for child components. The components are loaded via the vue-router. Different pages need the same data.

I import data from a JSON file and integrate it into vue with a "main.js":

//main.js
import Vue from 'vue'
import ...
import myData from './path/file.json' // [{},{},{}...]
Vue.prototype.$storage = myData
new Vue({ router, .....

Then I use in different components something like:

//pageX.vue
...
this.componentVar = this.$storage.filter((x) => x.name === 'needName')

And somehow it works. I worry if I'm doing the right thing. I am afraid of duplicating data in components or something like that, because my knowledge of javascript is deplorable :(

1 Answer 1

0

You have to use Vuex to store that data.. wheater immutable or not a state of an app has to a single absolute source of truth and no alternative compared to vuex can help you in this case

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this is still too difficult for me and for my project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.