Encountering an issue while attempting to retrieve information from Vuex store

I recently encountered an issue while trying to store my water data in Vuex. I followed the implementation below, but when I attempted to access my data array, it did not show up as expected.

const store = new Vuex.Store({
    state: {
        categories: {}
    },
    getters: {
        categories: (state) => {
            console.log(state.categories);
            return state.categories;
        }
    },
    mutations: {
        set_categories: (state, data) => {
            state.categories = data
        }
    },
    actions: {
        get_categories: (context) => {
            axios.get(`${baseUrl}/api/categories?pagination=0`)
                .then((response) => {
                    context.commit('set_categories', response.data);
                });
        }
    }
});

The code snippet above is how I incorporated everything into the component and accessed it.

mounted() {

        this.$store.dispatch('get_categories'); 
    },
computed: {
        stateCategories() { 
            return this.$store.state.categories 
        }
    },
console.log(this.stateCategories)

Surprisingly, despite confirming through Vue developer tools that my data exists in Vuex, I still cannot see it being displayed. Can anyone identify what might be causing this issue?

Answer №1

You should consider waiting for a response :

async mounted() {
    await this.$store.dispatch('get_categories'); 
},

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

Safari Glitch in Bootstrap 4

For a simplified version, you can check it out here: https://jsfiddle.net/dkmsuhL3/ <html xmlns="http://www.w3.org/1999/xhtml"> <title>Testing Bootstrap Bug</title> <!-- Bootstrap V4 --> <link rel="stylesheet" href="https://m ...

Implement a logging system to track and record data from both incoming requests and outgoing responses on a server powered by Express and Node.js

Is there a way for my server to log the response and request data when posting to another server? Thank you. const request = require('request'); postToIotPlatform = function postToIotPlatform(req, res, next) { var formData = JSON.stringify( ...

Tips for implementing a distinct texture on child elements through traversal techniques

My current dilemma involves working with an object that I've loaded using THREE.ObjectLoader(). This object consists of various elements, resembling a simple box made up of panels and sticks. My goal is to assign different textures to specific child ...

Clicking on a radio button can trigger the selection of another radio button

I'm currently working on a form that includes 8 radio buttons - 4 for System A and 4 for System B. The options for the buttons are CF, ISO, ISO-B, and NW. My goal is to create a functionality where selecting a radio button in System A automatically se ...

Retrieve the part of a displayed element

Presently, I am developing a modal system using React. A button is located in the sidebar and the modal is represented as a div within the body. In the render function of the main component of my application, two components are being rendered: MyModal M ...

Tips for eliminating empty trailing values and Carriage Returns from a JavaScript array

I needed a way to eliminate empty elements and Carriage Returns from the end of an array. Here's an example of what my array looks like: Input arr: ['', 'Apple', '', 'Banana', '', 'Guava', & ...

Dynamic background image that fills the entire webpage, adjusts to different screen sizes, and changes randomly

Currently, I am working on designing a web page with a dynamic background image that adjusts responsively in the browser without distortion. The challenge is to randomly select an image from an array using jQuery. Unfortunately, my knowledge of jQuery is ...

Is there a way to position the icon in the top left corner within the image using Vue and CSS?

I am currently working on a Vue project and I am attempting to create a row of images with an icon positioned at the top left corner of each image. Here is my code snippet: <div v-for="(image, index) in images" :key="index" class=&q ...

Utilizing WordPress Variables Beyond the Loop

Following the update of my loop to gather all necessary data using this code: <?php $json = ""; if ( have_posts() ) { while ( have_posts() ) { the_post(); global $wpdb; $query = "SELECT * FROM ". $wpdb-&g ...

No input value provided

I can't figure out what's going wrong. In other js files, this code works fine. Here is my HTML code: <table class='table'> <tr> <th>Event</th><td><input class='for ...

How can I retrieve the decimal x and y coordinates when the mouse is moved in Typescript Angular?

I am in the process of transitioning my user interface from Flash/Flex, where it stores values in decimal format. I need to access and reuse these values. Here is a demo showcasing my problem. Here is a snippet: import { Component, Input } from '@an ...

The definition of Csrftoken is missing

The code I am currently using, as per the recommended documentation, is: function csrfSafeMethod(method) { // these HTTP methods do not require CSRF protection return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); ...

Configuring Tailwind for Nuxt 3

I'm facing issues with setting up Nuxt 3 and every time I try to run the dev server, I encounter this error. I carefully followed the installation instructions provided in the Tailwind docs. ERROR Cannot restart nuxt: postcss@8 is not compatible with ...

I am experiencing an issue with my Nuxt + Tailwind setup where my custom tailwind.config.js file is not being applied, and the

After carefully following the official Tailwind + Nuxt documentation to integrate Tailwind into Nuxt, I successfully implemented it in 2 new projects and one existing Nuxt project. Unfortunately, I am facing an issue with the existing Nuxt project. The ex ...

Arrange the div underneath the link in Vue.js

I have a collection of dynamic hyperlinks generated in Vue.js <a class="block" href="#" @click="toggleNavigation(item)" v-for="item in skills" :key="item.id">{{item.name}}</a> and a Container that is placed absolutely <div style="position ...

Leveraging JavaScript to access the margin-top property of the HTML and body tags

I'm having trouble retrieving the "marginTop" style property from the <html> and <body> tags. While Chrome developer tools shows that margin-top is being set via in-HTML CSS: <style type="text/css" media="screen"> html { margin-top: ...

What is the process for importing a .gltf/.glb model into a Three.js application?

After browsing through several related topics on SO, I'm still unable to find a solution to my current issue. The problem I'm facing is that the .glb model simply refuses to load. My Vue application utilizes webpack (specifically the Quasar frame ...

Navigating through pages. Learning to jump between different sections by simply clicking on numbers

Can you guide me on how to link a button from a page numbered cycle so that it opens a specific page? I have figured out navigation using arrows, but switching between pages is tricky for me. The data is sourced from an API with a total of 98 posts availab ...

Steps for installing a package using npm without the need for configuring a package.json file

According to this source, it is feasible to install npm packages before creating the package.json file. After installing nodeJS on my computer, I attempted to run the following command in an empty directory: npm install jQuery This resulted in the follow ...

"Looking for a way to eliminate the background of an image on NextJS? Learn

https://i.stack.imgur.com/zAsrJ.png When this image is incorporated into a Nextjs rendering, it unexpectedly includes additional content. <div className="flex flex-col items-start justify-start rounded-3xl p-4 bg-boxi w-1/3"> <div cla ...