programing

Vuex 모듈에서 관찰자 유형 대신 개체 값 가져오기

yoursource 2022. 8. 13. 15:28
반응형

Vuex 모듈에서 관찰자 유형 대신 개체 값 가져오기

변환 내부의 Vuex 모듈 상태 값을 얻으려고 합니다.하지만 저는 항상 실제 객체 대신 옵저버 객체를 얻습니다.

@Module({
    namespaced: true,
    name: 'myModule',
    dynamic: true,
    store
})

export class MyModule extends VuexModule {
    public users: ArrayToObjMap<Users> = {};

    @Action
    public async initialize() {
      const fetchedUsers = await UsersService.getUsers();
      this.context.commit('setUsers', fetchedUsers);
    }

    @Mutation
    public setUsers(usersList: string[]) {
      this.users = GlobalUtils.mapIdsToItems(usersList, this.users)[0];
    }
}

Inside setUsers Mutation, 값this.users항상 옵저버입니다.반복할 수 있는 단순한 대상을 찾아야 해요.저는 이미 몇 가지 해결책을 시도했습니다.

  1. JSON.parse(JSON.strinfigy(this.users));=> 빈 개체를 반환합니다.
  2. cloneDeep(this.users);=> 빈 개체를 반환합니다.

언급URL : https://stackoverflow.com/questions/69820342/get-object-value-instead-of-observer-type-in-vuex-module

반응형