Reputation: 2256
store.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {},
getters: {},
mutations: {},
actions: {}
})
main.js
import Vue from 'vue'
import store from './store'
// What is purpose of store parameter in Vue instance?
const app = new Vue({
store
})
app.$mount('#app')
I have also seen similar syntax for Vue Router instance.
Upvotes: 0
Views: 649
Reputation: 1
The following syntax :
const app = new Vue({
store
})
makes the store instance available for the child components like this.$store
, if you don't do that the store will be not defined for your components or you have to import that store inside each one as :
import store from '../store'
//or
import store from '../../store'
which is not good practice.
Upvotes: 1