Uncaught ReferenceError: photoModule is not defined

Viewed 130

Uncaught ReferenceError: photoModule is not defined

Еhe first time I encountered such an error so that the vuex store does not find the module.

What could be the problem?

vuex

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

Vue.use(Vuex)

export default new Vuex.Store({

modules: {
photoModule
}
})

main.js

import store from './store'

Vue.prototype.axios = axios


Vue.config.productionTip = false

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

photoModule

import axios from 'axios'

export default {
    state: {
        photos: []
    },
    mitations: {
        setPhotos(state, payload) {
            state.photos = payload
        }
    },
    getters: {
        getAllPhotos(state) {
            return state.photos
        }
    },
    actions: {
        fetchPhotos(context) {
      
axios.get('https://jsonplaceholder.typicode.com/photos?_limit=10')
.then(response => this.photos = context.commit('setPhotos', response.data))
       
}
}
}

For the second day I have been sitting on this error. At least hint where something is wrong

1 Answers

You didn't import the module

import Vue from 'vue'
import Vuex from 'vuex'
import photoModule from './photoModule.js'  // ✅ Add this

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    photoModule
  }
})
Related