Entonces, mi problema es que parece que no puedo ver la variable coolEventScore cuando se carga la página. No sé si es algo que tiene que ver con los ciclos de vida, o tal vez estoy sobrecargando la funcionalidad dentro de la función vuex getListStats()... ¿Alguien podría arrojar algo de luz sobre esto?
cuenta.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"); } } }