[Vuejs]-Vuex doesn't work as expected – problem with import?

0👍

I went this way:
store.js:

export default new Vuex.Store({...})

main.js:

import store from './store'

new Vue({
  ...
  store,
  render: h => h(App)
}).$mount('#app')

Than in any component’s template: <span>{{this.$store.state.counter}}</span>.

Can’t confirm this is the best way, but it works for me.

0👍

your export and import don’t follow the ES6 rules,
if you are using export const store = new Vuex.Store({...})
you need to either import like this

import {store} from '../store.js'

if not, update your code to this:

import Vue from 'vue' import Vuex from 'vuex'

Vue.use(Vuex)

export default const store = new Vuex.Store({   state: {
    counter: 1   },   mutations: {
    increment(state) {
      state.counter++
    }   } })

Leave a comment