是否可以使用在同一模块中创建的state's property
初始化getter
?像这样:
export const gamesModule = {
state: {
games: [],
selectedGameID: null,
playerOnTurnID: this.getters.getSelectedGame.playerData[0]
},
getters: {
getGames: state => state.games,
getselectedGameID: state => state.selectedGameID,
getSelectedGame: state => getSelectedGameById(state.games, state.selectedGameID),
},
mutations: {
SET_GAMES (state, game) {
state.games.push(game);
},
SET_SELECTED_GAME_ID (state, id) {
state.selectedGameID = id;
},
SET_PLAYER_ON_TURN_ID (state, playerID) {
state.playerOnTurnID = playerID;
}
},
actions: {
async createGame({ commit }) {
try {
const { data } = await gameService.createGame();
commit('SET_GAMES', data);
} catch (error) {
console.warn('Error creating new game: ', error);
}
},
setSelectedGameID({ commit }, id) {
commit('SET_SELECTED_GAME_ID', id);
},
};
这样写,因为getters
未定义,所以不起作用。
答案 0 :(得分:0)
Option Explicit
Sub INPUT_DATA()
' INPUT_DATA Macro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim sourceWorksheet As Worksheet
Set sourceWorksheet = Worksheets("Input")
Dim destinationWorksheet As Worksheet
Set destinationWorksheet = Worksheets("Database")
With sourceWorksheet
If .Range("D55").Value = 0 Then
.Range("B2:AI52").Copy
With destinationWorksheet
.Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
End With
End If
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox ("File has been updated. DO NOT PRESS UPDATE again, as it will enter the same data once again")
End Sub
在对象的上下文中不存在,仅真正适用于构造函数或类。
我在这里看到两个问题。
首先,您不能引用对象本身,因为尚未定义它。在声明具有共同属性的对象(在本例中为getter函数)之前,您必须创建一个局部变量。
第二,更重要的是,我不确定它是否有助于访问getter(Reducer)函数,因为它不了解状态,底层Vuex库将该状态作为第一个参数传递给它处理突变(操作)时。
Vuex基于Redux模式,即Action-> Reducer-> Store,我建议您阅读一下有关Redux工作原理的快速介绍,因为它将帮助您更好地了解Vuex内部的动作流程。 >