Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
Dom not updating Vuex state variable

So my issue is that I cannot seem to see the variable coolEventScore when page loads. I do not know if it something that has to do with lifecycles, or maybe I am overloading functionality inside the vuex getListStats() function... Could anyone bring some light to this?

account.js

import Vue from 'vue'

import {achost} from '../constants';

const state = () => ({
    coolEventScore: {}
});

const actions = {
    getListStats(context) {
        return Vue.axios.get(
            `xxxx/xxxx`, {}, {
                headers: {
                    'XXXX': 'xxxx',
                    'XXXX': xxxx
                }
            }).then((resp) => {
                let events = resp.data['event_info'];
                let coolEvt = events.filter(evt => evt.src === "coolEvt")[0];
                let coolEvtScore = coolEvt .score;
                context.commit("setCoolEventScore", coolEvtScore)
                return events;
            }).catch((err) => {
                console.log(err)
            })
    },
}

const mutations = {
    setCoolEventScore(state, value) {
        state.coolEventScore = value;
    }
}

export const account = {
    namespaced: true,
    actions,
    mutations,
    state
}

Cool.vue

<template>
    <div>
        <span :html="coolEventScore"></span>
    </div>
</template>

<script>
import store from "../../../store";
import { mapState } from "vuex";
import { account } from "../../../store/modules/account";

if (!store.state.account) store.registerModule("account", account);

export default {
  name: "Cool",
  components: {},
  created() {
      this.fetchEvents();
  },
  computed: {
    ...mapState("account", {
        coolEventScore: (state) => state.coolEventScore
    }),
  },
  methods: {
    fetchEvents() {
        this.$store.dispatch("account/getListStats");
    }
  }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda