刚刚开始玩ngxs并且遇到了障碍。我不知道我做错了什么,但我得到'状态未定义'的错误。
行动:
const prefix = "[Tutorial]";
export class AddTutorial {
static readonly type = `${prefix} Add Tutorial`;
constructor(public payload: string) { }
}
州:
export class TutorialStateModel {
tutorial: any[]
}
@State<TutorialStateModel>({
name: 'tutorial',
defaults: {
tutorial: [],
}
})
export class TutorialState {
@Action(AddTutorial)
addTutorial({ getState, patchState }: StateContext<TutorialStateModel>, { payload }: AddTutorial) {
const state = getState();
patchState({
tutorial: [...state.tutorial, payload]
});
}
}
错误指向:const state = getState();
零件:
ngOnInit() {
this.store.dispatch(new AddTutorial('Redux'));
}
这是我的缓存。我清除它现在它的工作原理。