It looks like you're trying to create a Vuex module and then use it within your main store. However, there's a mistake in how you're defining your apiModule. Instead of using createStore for your module, you should define it as a plain object. The createStore function is used to create the main store instance, not for individual modules.
Here's how you can correct your apiModule.js:
import axios from 'axios';
const apiModule = {
namespaced: true,
state: {
items: null
},
getters: {
getItems: (state) => state.items
},
mutations: {
setItems(state, items) {
state.items = items;
}
},
actions: {
async fetchData({ commit }) {
try {
const result = await axios.get('http://mcc-be.local/api/auth/sw_version');
commit('setItems', result.data);
} catch (error) {
console.error(error);
}
}
}
};
export default apiModule;
And your store/index.js looks fine, but just to reiterate, it should look like this:
import { createStore } from 'vuex';
import apiModule from './modules/apiModule';
export default createStore({
modules: {
api: apiModule
}
});
With these changes, your module should be correctly defined and the error you're encountering should be resolved. Your HomeComponent.vue should now be able to access the itemsFromStore computed property without any issues.