【发布时间】:2021-06-01 08:43:18
【问题描述】:
我有数据要在不同的场景中填充和更新。 在这些情况下,我需要填充“href”和“href2” 每当我尝试按照下面的代码进行填充时,我都会得到
-
Uncaught TypeError: Cannot read property 'getters' of undefined - (试图从 getter 中引用)
-
从兄弟 Vuex 状态数据引用时也是如此未捕获的类型错误:无法读取未定义的属性 'locationId'
这是来自我的 Vuex 商店的示例 sn-p。
注意:我试图做的这个参考/调用是在我的 Vuex 商店中。
我需要知道如何在 Vuex Store 中正确引用这些数据的帮助。 提前谢谢你。
export default new Vuex.Store({
state: {
defaultLocationId: "/...",
updatedLocationFromAction: "",
navData: [
...,
{
title: "Location",
icon: "fa fa-map-marker",
href: "/locations/" + this.defaultLocationId,
href2: "/locations/" + this.getters.anotherLocation,
},
...,
],
},
getters: {
anotherLocation(state) {
return state.updatedLocationFromAction;
},
},
});
【问题讨论】:
标签: javascript vue.js vuex