The Vue template fails to reflect any changes in the Pinia store state

I am currently in the process of upgrading a Vue 2 application to Vue 3. The transition has been smooth so far, however, I am encountering an issue where the templates are not updating based on the Pinia state. I have searched through other Stack Overflow questions regarding this matter but have been unable to find a solution.

Below are my components (parent and child) and store - Please note that I am using the options API

// Parent
<template>
  <div class="wrapper">
    <ActionButtonGroup />
  </div>
</template>

<script>
import { useActionStore } from '@/stores/ActionStore';
import ActionButtonGroup from './components/ActionButtonGroup/main.vue';
export default {
  name: 'ActionsParent'
  components: {
    ActionButtonGroup,
  },
  created() {
    this.loadActions();
  },
  methods: {
    loadActions() {
      useActionStore().loadActions();
    },
  }
}
// Child
<template>
  <div class="action-buttons d--f ai--c">
      <Spinner class="ml-3" v-if="loading" />
  </div>
</template>

<script>
import { mapState } from 'pinia';
import { useActionStore } from '@/stores/ActionStore';
import { Spinner } from '@/components/index';

export default {
  name: 'ActionButtonGroup',
  components: {
    Spinner,
  },
  computed: {
    ...mapState(useActionStore, ['loading']),
  }
}
</script>
// Store
import { ActionApi } from '@/api/index';
export const useActionStore = defineStore('Action', {
  state: () => {
    return {
      loading: false,
    };
  },
  actions: {
    async loadActions() {
      this.loading = true;
      await this.fetchActions();
      this.loading = false;
    },
    async fetchActions(id) {
      const actions = await ActionApi.fetchActions();
      return actions;
    },
  }
}

I have also attempted using a setup function in the child component, but unfortunately, it did not resolve the issue:

setup() {
    const store = useActionStore();
    const loading  = computed(() => store.loading);
    return {
      loading
    }
  },

Answer №1

Regrettably, I am unable to provide a comment at this time, so I will respond with an answer instead.

Upon investigation, it appears that the issue may not be related to Pinia. After thorough testing and recreation, everything seems to be functioning correctly. I recommend exploring other potential areas of concern, such as your Vue instance and the specific function being invoked. It may be beneficial to strip down the code to its essentials in order to identify any discrepancies. Additionally, ensure that the "fetchActions" function is properly executing after the "await" statement and that the state is indeed updating.

If the state is successfully updating, then the problem likely lies within the Vue instance. In this case, consider reconstructing the functionality within a separate Vue instance to pinpoint the root cause of the issue.

I trust that these suggestions prove to be useful in resolving the issue!

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

A guide to iterating over an array and displaying individual elements in Vue

In my application, there is a small form where users can add a date with multiple start and end times which are then stored in an array. This process can be repeated as many times as needed. Here is how the array structure looks: datesFinal: {meetingName: ...

Transform a fabricjs canvas into a base64 encoded image

I am attempting to transmit a canvas as an image to my server in base64 format. While Fabricjs provides options such as canvas.toSVG() or canvas.toDataURL({format: 'image/png'}) to convert the canvas to an image, the output I see in my console ap ...

Instructions on declaring a Typescript variable that will only be assigned once in the future

In the land of coding, there are two constants: const which sets a value at declaration, and let which allows for variables to be changed. But what about a special Typescript (or javascript) variable that starts as undefined, and once defined, remains fo ...

Substituting placeholders within a docx template remains incomplete

Utilizing this specific library, I am implementing a feature to substitute placeholders within a docx template and generate multiple documents. The technologies involved are neutralino and vue for the front-end, where I have devised a method that transmits ...

AngularJS encountered an error while attempting to load a template: [$compile:tpload]

After developing my angularjs example app in my netbeans ide based local server, I encountered an issue when I tried to move the application to an nginx server. The browser displayed the following error message: Error: [$compile:tpload] Failed to load tem ...

Integrating *.vue file compatibility into the Shopware 6 Storefront (Encountering issue with 'vue-loader' not being resolved)

I am looking to integrate a mini Vue app into the Shopware 6 storefront within the TWIG ecosystem. This is what I have accomplished so far: MyPluginTheme\src\Resources\app\storefront\build\webpack.config.js const { join, reso ...

What is the reason for Cypress choosing to omit specific commands?

The test below aims to scan and authenticate a QR code, then utilize the received authentication token. However, for some reason, the last two commands (.type) are not being executed. I've been stuck at this point for quite some time now. Any insights ...

Implementing a button disable feature in Vuejs until email validation is complete

new Vue({ el: '#app', data: { email: '' }, computed: { isEmailValid() { return '/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ...

Modifying worldwide variables within an ajax request

After spending considerable time attempting to achieve the desired outcome, I am faced with a challenge. My goal is to append the object from the initial ajax call after the second ajax call. However, it appears that the for loop is altering the value to ...

Leveraging Async/Await in NodeJS within Array.map alongside an 'if' condition

Within my code, there is a recursive function that iterates over an object. It specifically searches for keys labeled subcomponent (always containing an array) and executes an asynchronous task on each child within subcomponent, using the output to replace ...

Having trouble with loading JSON due to a Cross-Domain AJAX problem

I am facing a challenge with a URL that I do not have control over, which returns a JSON string. Within this JSON string, there is a URL that I am attempting to load using JavaScript/jQuery AJAX. However, I am encountering a Cross-Domain issue while trying ...

What is the method for obtaining a dynamic route path within the pages directory in Next.js?

In my code, I have a special Layout component that compares routing queries and displays the appropriate layout based on the query. I'm looking to extend this functionality to handle dynamic routing scenarios, such as invoices/invoice-1. Currently, ...

Leveraging TypeScript modules without the need for require()

I created a TypeScript 2.3 app called app.ts that requires the Vue.js library version 2. I manually added the Vue.js script src in the HTML file. All I wanted was to use Vue.js with type checking. I thought I could simply reference it like this: /// & ...

Generate an array of HTML files from external sources and randomize their placement within multiple div containers

I am currently working on a website that features a grid made up of divs (4x4) which need to have a set of texts shuffled into them every time the page is reloaded. You can see what it looks like here. Within my index.htm file, I have the following struct ...

Prioritizing tasks, always giving a call once they are completed

I am trying to populate an HTML snippet with data from Firebase. Here is the JavaScript code I wrote to achieve this: members.forEach(el => { console.log(el) table_number++; console.log("forEachMember" + table ...

Starting the download of the canvas featuring a stylish border design

I'm facing an issue where the canvas border is not showing up when I download the canvas with a border. The border appears on the screen, but it doesn't get included in the downloaded canvas. let canvas=qrRef.current.querySelector("canvas&qu ...

Tips on how to direct the attention to a text box within a unique dialog, ensuring that the blinking cursor highlights the input area

Is there a way to set autofocus on a textbox when opening a custom dialog box? I've tried using the autofocus attribute for the input field, but it doesn't seem to work for me. Can anyone provide guidance on how to achieve autofocus for a textfie ...

I am encountering difficulties displaying the image and CSS files from another folder in my HTML with Node.js

I am facing difficulty in establishing a connection between my front-end and back-end using node.js. As a result, the website only displays the HTML code without linking to the CSS or image files. Here is the folder structure: root -src •pi ...

Exploring the functionality of Vue.js through Jasmine without the use of JavaScript modules

My task involves investigating unit testing for JavaScript on an older application that does not utilize JS modules (import/export). The app contains JS object/prototypes in external .js files that are imported via script src, and more recently, some Vue 2 ...

Does v-if cause the jquery clock picker to malfunction?

Here is my unique div where the clockpicker library functions correctly. <div class="input-group clockpicker"> <input type="text" class="form-control" value="18:00"> <span class="input-group-addon"> <span class ...