Skip to content

TypeError: commit is not a function #108

@oliviermattei

Description

@oliviermattei

Hello, when i'm trying to use the store I have this error

proxy.js?fe19:354 Uncaught (in promise) TypeError: commit is not a function

here my code

import { action, createModule, mutation } from 'vuex-class-component';
import { Country } from '@/interfaces/country';
import { CountriesAdapter } from '@/adapters/countries.adapter';
import axios from 'axios';

const VuexModule = createModule({
  namespaced: 'Countries',
  strict: false,
});

export class CountriesStore extends VuexModule {
  private countries: Country[] = [];

  @mutation
  clear() {
    this.countries = [];
  }

  @mutation
  setCountries(payload: Country[]) {
    this.countries = payload;
  }

  @action
  async getCountries(forceRefresh = false) {
    const { data } = await axios.get(`${process.env.VUE_APP_COUNTRIES_API_URL}/countries`);

    const response = CountriesAdapter.get(data);

    this.setCountries(response);
    return response;
  }

  // Explicitly define a vuex getter using class getters.
  get getCountriesList() {
    return this.countries;
  }
}

And in my component

 mounted() {
    this.$store.dispatch('Countries/getCountries');
  }

I don't where is the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions