Error: Unrecognized action type in Vuex

I've been encountering some major issues with vuex lately. For some reason, getters, actions, and mutations are not being recognized. In the code snippet below, although fetchFacilities is working fine, addFacility is throwing an error: [vuex] unknown action type: addFacility (from store.ts)

//...
actions: {
  addFaciltiy: async function (context, fac: CFacility) {
    await axios.post('/db/facilities', fac)
  },
  fetchFacilities: async function (context, actions) {
    axios.get('/db/facilities').then((response) => response.data.forEach((element: CFacility) => {
    context.commit('addFacility', element);
  }));
}
//...

(from the vue component)

import Vue from "vue";
import { CFacility } from "./model";
import { mapGetters, mapActions } from "vuex";

export default Vue.extend({
    //...
      methods: mapActions(["fetchFacilities", "addFacility"]),
    //...
    created() {
      this.fetchFacilities("a");
      this.addFacility(
        new CFacility(//..)
    );
}}

I am using the autogenerated store.ts. I have read through countless posts of people messing up modules and their namespaces, which I don't use. I tried arrow notation for the actions, rewrote the actions multiple times and accessed them via dispatch and via mapActions.

Answer №1

One helpful tip is to include ellipsis before mapActions:

methods: ...mapActions(["fetchFacilities", "addFacility"]),

Answer №2

Only a minor error, big thanks @daniel ormeño

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Angular 2 Type Script service, make sure to include the @angular/core module for proper functionality as the 'require' method may not

I am encountering an issue with a service I am using. Whenever I try to start the page, I receive an error message. Here is the screenshot of the error: The compiled .js file contains the following code: reuired('@angular/core') Any suggestion ...

Do not expect Vue.js and javascript to cooperate

I've encountered an issue with my JavaScript and Vue.js code that is proving to be more complicated than expected. I'm struggling to set a height for an element using JavaScript, and every time I attempt to do so, I receive the error message &apo ...

Shut down the tab or browser window containing information on vue

When attempting to log off a user by closing the page and browser, I encountered difficulty. 1. window.onunload; 2. window.onbeforeunload. window.onunload = function() { differTime = new Date().getTime() - beginTime; if (differTime <= 5) { cle ...

The issue appears to be a missing space before the function parentheses in the

I am just getting started with learning Vue.js. During my project setup, I encountered an issue related to the "Missing space before function parentheses" error message. Below are the details of the 3 errors that I came across: ✘ http://eslint.org/docs ...

What is causing Angular to consistently display the first object in the array on the child view, while the child .ts file correctly prints information from a different object?

Once a card of any object is clicked, the information of that specific object will be printed to the console. However, the child view will only display the details of the first object in the array it retrieves from. All pages are included below. A visual e ...

Arranging the output of a Typescript project

I'm currently advocating for Typescript to be implemented in our web application. Can anyone provide insight on the best method for structuring Javascript output files? Should they be excluded from source control? And when it comes to testing, is it p ...

The form doesn't seem to be functioning properly when I incorporate the formgroup and service within the ngOnInit() method

I implemented the formgroup code in ngOnInit() and also utilized a service in ngOnInit(). However, the asynchronous nature of the form is causing issues. The full code on StackBlitz works when I use dummy JSON data within the constructor. Check out the wor ...

An easy method to define argument types for every function type in TypeScript

How can I assign argument types to each function type in TypeScript? Each function has a parameter associated with it. [Example] type F1 = (arg: number) => void; type F2 = (arg: string) => void; const caller = (f: F1 | F2) => (n: number | strin ...

Avoiding caching of GET requests in Angular 2 for Internet Explorer 11

My rest endpoint successfully returns a list when calling GET, and I can also use POST to add new items or DELETE to remove them. This functionality is working perfectly in Firefox and Chrome, with the additional note that POST and DELETE also work in IE ...

Highlighting in Coda on MacOS now supports TypeScript

Can anyone help me with getting my Coda editor to properly highlight TypeScript? I checked this page and it says that TypeScript is supported: But in my up-to-date version of Coda, the list of supported languages seems different. Is there a way to make Ty ...

"Enhancing the edit functionality of *.Vue components within Laravel: A comprehensive guide

I am new to Vue and seeking some assistance. I have a Laravel code integrated with Vue, and I am trying to make changes to the navbar.vue component. However, whenever I add or remove something and save it, there is no update reflected in the HTML of the ...

What is the reason for the function to return 'undefined' when the variable already holds the accurate result?

I have created a function that aims to calculate the digital root of a given number. Despite my efforts, I am encountering an issue where this function consistently returns undefined, even though the variable does hold the correct result. Can you help me ...

Using nested v-for loops in Vue.js

Is there a way to access individual object items within a nested object using v-for in Vue.js? This is the data structure: flights: [ { "airline": "BA", "airport": "EBJ", "status": { "_code": "A", "_time": "2018-03-02T14:19:00Z" ...

What could be causing my Angular2 component to not properly use my template?

I have two components that I am working with. The first component is: import {Component} from 'angular2/angular2'; import {Navbar} from './navbar'; @Component({ selector: 'app' template: `<div class="col-md-12"> ...

Vue warning: Issue encountered in created hook - Attempting to access property 'get' of an undefined variable is causing a TypeError

I encountered an error while using axios: [Vue warn]: Error in created hook: "TypeError: Cannot read property 'get' of undefined" export default { methods: { loadUsers(){ axios.get("api/user").then(data => ...

What is the best way to display information related to a specific id in Vue.js?

Currently, I have all the records displayed on a page located at this URI xxx.test/employer/search/filter-by. The display of these records is powered by Algolia Search, and there is a button labeled View Profile, which triggers an empty method named showPr ...

What is the process for defining a global variable within a module in Typescript?

I've already included a global value in my global JavaScript context: const fs = require('fs') For a specific reason, I need to include it in the global scope. Now, I want to create a .d.ts file to declare the global variable with a stron ...

Experimenting with Vuejs by testing a function that delivers a Promise upon the execution of the "Created" hook

In my Vuejs application, I have the following script written in Typescript: import { Foo, FooRepository } from "./foo"; import Vue from 'vue'; import Component from 'vue-class-component'; import { Promise } from "bluebird"; @Component ...

Nuxt.js: Streamlining multiple websites/domains within a single project

Imagine a scenario where we have three distinct websites named website A, website B, and website C. Each of these websites will reside on their own domain, namely mypage-a.com, mypage-b.com, mypage-c.com. The framework that is being utilized here is nuxt.j ...

Having trouble with errors when adding onClick prop conditionally in React and TypeScript

I need to dynamically add an onClick function to my TypeScript React component conditionally: <div onClick={(!disabled && onClick) ?? undefined}>{children}</div> However, I encounter the following error message: Type 'false | (() ...