• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

271
Views
NUXT Properties from Vuex are not getting updated in DOM when using async actions

For demonstration purposes, I created a small test page and store. According to the code, it should show count = 1, then 500ms later count = 2 as the store updates.

Here's my test.vue:

<template>
  <div>count = {{ count }}</div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  layout: "test",
  computed: {
    ...mapGetters({ count: "test/count" }),
  },
  mounted() {
    this.$store.dispatch("test/updateCount");
  },
};
</script>

store/test.js

export const state = () => ({
  count: 1
});

export const getters = {
  count(state) {
    return state.count;
  }
};

export const actions = {
  updateCount(context) {
    setTimeout(() => {
    context.commit("setCount", 2);
    }, 500);
  }
};

export const mutations = {
  setCount(state, value) {
    state.count = value;
  }
};

But the result is always count = 1 in DOM

In vue devtools, both vuex bindings and vuex state show count = 2, but its not updated in DOM.

However, it works if I remove the setTimeout function in actions.

Am I doing anything wrong?

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I am working on a Japanese website, so I had google translations turned on during development, which was probably interfering with it. I turned it off and its working now!

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error