javascript - Vuex getter 未定义,但 store 有正确的数据
问题描述
我正在改变数据并确认 $store 已正确更新,但 getter 仍未定义。我正在使用 vue-dev-tools 进行故障排除。我FETCH_ENDPOINTS
从加载的第一个组件调用。
有趣的事实:如果我关闭浏览器并冷加载应用程序,getter 就会有数据。如果我刷新页面,getter 是未定义的。
Vuex 模块:
const getters = {
agentEndpoints: state => state.agent.agentEndpoints
};
export const actions = {
[FETCH_ENDPOINTS](context) {
CcpService.getEndpoints().then(endpoints => {
console.log("action: " + JSON.stringify(endpoints)); // This has the right data!
context.commit(SET_ENDPOINTS, endpoints);
});
}
};
export const mutations = {
[SET_ENDPOINTS](state, endpoints) {
console.log("mutation: " + JSON.stringify(endpoints)); // This has the right data!
state.agent.agentEndpoints = endpoints;
}
};
解决方案
推荐阅读
- ssl - TLS 连接的 CA 证书 node02.myqtthub.com/8883
- flutter - Flutter - 当想要更改初始值时,TextFormField 崩溃应用程序
- php - 如何将增量运算符连接到 PHP
- c# - 出了点问题“错误 CS1513:} 预期”
- java - 如何计算所有用户输入数据的费用?
- mysql - MySQL reset id custom id based on current year
- python - 修改数据框图上的 x 轴值
- powershell - 如何将Windows窗体文本框输入传递给powershell模块功能
- c# - 如何有条件地将多个模型映射到 ASP.NET Core Identity 中的一个表(AspNetUsers)?
- excel - 如何在 Excel VBA 中显示警报消息?