vedmant / nuxt3-vuex

Vuex store feature for Nuxt3
https://nuxtjs.org/docs/directory-structure/store/
MIT License
24 stars 11 forks source link

Can not find actions name in store when call $store.dispatch('fetchCounter', data) #14

Open krol-m2 opened 9 months ago

krol-m2 commented 9 months ago

I have converted nuxt2 store/index.js to nuxt3 store as below store/index.js

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

const getters = {
  getCounter(state) {
    return state.counter
  }
}

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

const actions = {
  async fetchCounter({ state }) {
    // make request
    const res = { data: 10 };
    state.counter = res.data;
    return res.data;
  }
}

const store = new useStore({
  state,
  getters,
  mutations,
  actions,
})

export default store

plugin/vuex.js

import store from '~/store'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(store)
})

when i call $store.dispatch('fetchCounter', data) then it inform error can not find action. pls help me take a look at store/index.js if any error missing config

krol-m2 commented 9 months ago

Cannot set property $store of # which has only a getter

it inform error like this