H
H
hckn2019-01-06 18:43:40
Vue.js
hckn, 2019-01-06 18:43:40

How to import a store into an external file?

Nuxt uses and recommends the Vuex model system

// store/index.js

export const state = () => ({
  counter: 0
})

export const mutations = {
  increment (state) {
    state.counter++
  }
}

And how then to use the store in external files if we do not export it? gives an error
import store from '@/store'
"export 'default' (imported as 'store') was not found in '@/store'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fl3nkey, 2019-01-07
@FLUNKEY

I will say that unfortunately you can’t do without crutches, because. this is not specifically provided by nuxt itself. There are a couple of such solutions:
adin
two
The first one is from the nuxt developer himself, such a solution.
The second one is more or less.
I recommend designing the application correctly from a nuxt point of view, and not trying to do things that the framework doesn't provide.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question