Issue with Vuex causing error message "TypeError: Unable to access property 'getters' of an undefined object"

I am facing an issue where Vuex seems unable to locate my getter for the loading_state.

While the vuex state and getter are visible in the Vue developer tools, I am unable to access them within my application.

I have attempted to make changes such as modifying variable names and trying different methods to call the getter.

loading_store.js

import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export const loading_store = new Vuex.Store({
    state: {
        loading: true
    },
    mutations: {
        setFalse(state) {
            state.loading = false;
        },
        setTrue(state) {
            state.loading = true;
        }
    },
    getters: {
        isLoading: state => {
            return state.loading;
        }
    }
});

App.vue

<template>
    <div id="app">
        <Navigation />
        <loading-spinner v-if="isLoading" />
        <router-view class="m-3" />
    </div>
</template>

<script>
import Navigation from "@/components/Navigation";
import LoadingSpinner from "@/components/LoadingSpinner";
import { mapGetters } from "vuex";

export default {
    name: "app",
    components: {
        LoadingSpinner,
        Navigation
    },
    metaInfo: {
        title: "SnowStats"
    },
    computed: {
        ...mapGetters(["isLoading"])
    }
};
</script>

main.js

import Vue from "vue";
import App from "./App.vue";
//////////
import { loading_store } from "./state/loading_store";

/////////

new Vue({
    state: loading_store,
    router,
    render: h => h(App)
}).$mount("#app");

Error messages:

    vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'getters' of undefined"

    found in

    ---> <App> at src/App.vue
           <Root>


    TypeError: Cannot read property 'getters' of undefined
        at VueComponent.mappedGetter (vuex.esm.js?2f62:896)
        at Watcher.get (vue.runtime.esm.js?2b0e:4473)
        at Watcher.evaluate (vue.runtime.esm.js?2b0e:4578)
        at VueComponent.computedGetter [as isLoading] (vue.runtime.esm.js?2b0e:4830)
        at Object.get (vue.runtime.esm.js?2b0e:2072)
        at Proxy.render (eval at ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"34f9cbf8-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/App.vue?vue&type=template&id=7ba5bd90& (app.js:947), <anonymous>:13:11)
        at VueComponent.Vue._render (vue.runtime.esm.js?2b0e:3542)
        at VueComponent.updateComponent (vue.runtime.esm.js?2b0e:4060)
        at Watcher.get (vue.runtime.esm.js?2b0e:4473)
        at new Watcher (vue.runtime.esm.js?2b0e:4462)

Answer №1

I am confident that the accurate syntax should be

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

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

Executing a command efficiently in Javascript with the get method

The command that needs to be sent to the embedded device is in the form of a GET method. However, the value continuouspantiltmove: String(pt) is not being properly transmitted to the CGI script through Google Chrome, causing it to fail. Since I do not hav ...

Encountered an issue while setting up ng-circle-progress in Angular: Unable to find an exported member in

I am currently working on incorporating the ng-circle-progress functionality by referring to the documentation at https://www.npmjs.com/package/ng-circle-progress. Here is a snippet from the .ts file: import { Component } from '@angular/core'; i ...

"Enhancing JqGrid functionality with inline editing and custom formatters

I'm currently working with a column model that looks like this: { name: 'CostShare', index: 'CostShare', width: 50, formatter: 'number', formatoptions: { decimalPlaces: 2, suffix: "%" }, resizeable: true, align: 'ce ...

Why isn't the page being redirected when attempting to use JavaScript with window.location and window.location.href?

Currently, I have implemented a login system on my website. The process involves triggering an ajax request to a designated PHP script upon the user clicking the submit button. This script is responsible for logging in the user and responding with the mess ...

Prevent the Swiper slider from autoplaying while a video is being played, and automatically move to the next slide once the video is paused or

<div class="swiper mySwiper"> <div class="swiper-wrapper"> <div class="swiper-slide"> <video-js id="6304418462001" class="overlayVideo" data-account= ...

How can you transform square bracket object keys from a URL address into a nested object using Javascript?

Considering the following: var obj = { "object[foo][bar][ya]": 100 }; Is there a way to achieve this structure: var obj = { object: { foo: { bar: { ya: 100 }}}}; ...

Locate the final element within an array using JavaScript

Provided with a file path like new/lib/java.exe, I am looking to eliminate the root folder 'new' and structure the new path as lib/java.exe. Challenge: After my attempts, I am left with the path as lib/java.exe/ which includes an unwanted "/". I ...

What are some reasons for the slow performance of AWS SQS?

My current project involves measuring the time it takes to send a message and receive it from an SQS queue. Surprisingly, the average time it takes is between 800-1200 ms, which seems like an excessively long period. Below is the code I have been using for ...

unable to execute grunt post npm installation

I'm having trouble getting grunt to work on my system. I tried installing it using npm install grunt -g It appears to have installed successfully - <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b3a6a1baa094e4fa0bbe7 ...

Using the find() function in Mongoose allows the use of a variable as a model

Would it be feasible to employ a variable in place of the model name when using the find() function in mongoose? For instance, if my website is capable of displaying photos and videos based on the last part of the URL, which could be either /photo or /vide ...

How can I implement a page switch in vuejs by clicking on a name in a table list?

I'm currently working on a list page in VueJS and facing some challenges. Here is the code snippet: <template> <vue-good-table :columns="columns" :rows="row" :search-options="{ ...

Error: Cloudant encountered a problem processing your request

Why is my attempt to upload JSON objects into a Cloudant database resulting in a "400 bad request" error? pos = { 'lat': position.coords.latitude, 'long' : position.coords.longitude }; $.ajax({ type: "POST", ...

Vue-2 Jest-24 is encountering a test error, specifically a SyntaxError due to encountering an unexpected character, '#'

Issues Encountered with Jest Testing in Vue 2 Hello everyone, I'm currently facing difficulties while trying to run tests for my Vue 2.6 application. Specifically, I am having trouble writing tests that involve the usage of the Router and TypeScript ...

The server failed to start with exit code 1 - Command execution terminated

Upon my initial attempt to launch a server from vite (vue/javascript), I encountered the exit 1 code error. Despite successfully installing the latest versions of vite/vue globally (vue 3.4.21, @vitejs/plugin-vue 5.0.4, vite 5.2.6). I have gone the route ...

creating a fresh window using AJAX in Ext JS

While I know there may be similar questions out there, the details of my situation are unique. I'm facing an issue with building a new window using ExtJS, starting from a pre-existing grid. The goal is to populate this new window with references to el ...

What is the best way to delete comments from the config.js file?

I'm looking for a way to remove comments from my config.js file, which is acting as a JSON file in my project. The config file has both single line comments like this: //comment goes here and multi-line comments like this: /* comments goes here */ ...

Splitting an array into multiple arrays with distinct names: A step-by-step guide

I have a data set that looks like this: [A,1,0,1,0,1,B,1,0,0,1,A,1]. I want to divide this array into smaller arrays. Each division will occur at the positions where "A" or "B" is found in the original array. The new arrays should be named with the prefix ...

Develop a personalized event that is compatible with all types of selectors

If I have a simple script that changes the background color of an element when clicked: $(".foo").on("change.color", function() { $(this).css("background-color", "red"); }); $(".foo").click(function() { $(this).trigger("change.color"); }); Currently ...

Endless Loop Encountered When Attempting to Split a Vuex Array

If you want to check out my codesandbox setup, you can find it here. In this setup, three dates should be printed. The important parts of the code are as follows: import Vue from "vue"; import App from "./App"; import Vuex from "vuex"; Vue.use(Vuex); co ...

Assign values to variables in a JavaScript file using node.js

My tech stack includes node.js, express.js, and either pug or jade. Within my server, I inject a variable called pageId into a view. In the pug view, I utilize this variable using the following script: script. document.addEventListener('DOMConten ...