shamsmosowi / git-bot

0 stars 0 forks source link

Cannot read properties of undefined (reading 'getters') #37

Open bofeiw opened 1 year ago

bofeiw commented 1 year ago

Can anyone help with the below, I am getting the following error Cannot read properties of undefined (reading 'getters')

I am working on a project where my stores should return an array to my index.vue

Is there also any way I can get around this without having to use the Vuex store?

My store directory contains the below files

index.js

export const state = () => ({}) parkingPlaces.js

import {getters} from '../plugins/base'

const state = () => ({ all: [] });

export default { state, mutations: { SET_PARKINGPLACES(state, parkingPlaces) { state.all = parkingPlaces } }, actions: { async ENSURE({commit}) {

    commit('SET_PARKINGPLACES', [
      {
      "id": 1,
      "name": "Chandler Larson",
      "post": "37757",
      "coordinates": {
        "lng": -1.824377,
        "lat": 52.488583
      },
      "total_spots": 0,
      "free_spots": 0
    },
    ]
    )
  }
},

getters: { ...getters } } index.vue

base.js

import getters from "./getters";

export {getters};

getters.js

export default { all: state => state.all }; Image of my file directory below enter image description here

image of error enter image description here

shamsmosowi commented 1 year ago

Hi,

It looks like you are trying to access the getters property of the parkingPlaces store, but it is undefined. When you export the default object of the parkingPlaces.js store, you need to include the getters property.

You can add the getters property to the parkingPlaces.js store as follows:


export default {
  state,
  mutations: {
    SET_PARKINGPLACES(state, parkingPlaces) {
      state.all = parkingPlaces
    }
  },
  actions: {
    async ENSURE({commit}) {

        commit('SET_PARKINGPLACES', [
          {
          "id": 1,
          "name": "Chandler Larson",
          "post": "37757",
          "coordinates": {
            "lng": -1.824377,
            "lat": 52.488583
          },
          "total_spots": 0,
          "free_spots": 0
        },
        ]
        )
      }
    },
  getters: {
bofeiw commented 1 year ago

@shamsmosowi seems like the answer is cut off half way, what happened to the ai?