In Vue, you can store commonly used variables and methods in the base Vue instance. This way other components can access this data.
new Vue({
data: {
name: 'John'
}
});
If you are using Vuex for state management you could also store this data here as well.
const store = new Vuex.Store({
state: {
name: 'John'
}
}
From my understanding, Vue mixins also offer the same functionality (allowing any component to access this commonly shared data globally).
Vue.mixin({
data() {
return {
name: 'John'
};
}
});
My question is when should you use the base Vue instance over Vuex or a global mixin?
data
property in the rootVue
instance should not be a function. 2) The mixin data will not be shared, it will be merged into a component's data each time it is created. 3) Any answer to question will be opinion-based as the question itself is too broad / subjective – Phil