itsource

store getter가 null 대신 옵서버 개체를 반환합니다.

mycopycode 2022. 8. 29. 22:21
반응형

store getter가 null 대신 옵서버 개체를 반환합니다.

간단한 "Conway's Game of Life" 응용 프로그램을 만들고 이미 설정한 설정을 localStorage에 저장하고 싶습니다.

3개의 뷰를 작성했습니다.

  • Map Settings | 맵사이즈 정의 등

  • Map Setup | 지도 사전 설정 만들기

  • Map Launch | 프리셋 부팅

설정이 변경될 때마다 사전 설정의 이전 크기가 다를 수 있으므로 사전 설정을 삭제해야 합니다.localStorage가 비어 있으면 설정에 기본값이 사용됩니다.

내 스토어에서 지도 설정을grid소유물.이 값은 다음 중 하나입니다.null또는 local Storage의 2차원 어레이를 사용합니다.

MapSetup.vue 파일로 라우팅할 때 마운트된 이벤트를 사용하여 사전 설정을 설정합니다.

  mounted: function() {
    if (this.grid) { // the preset from the store / localStorage
      this.currentGrid = this.grid; // use the preset
    } else {
      this.currentGrid = this.generateNewMap(); // generate a new preset
    }
  }

불행하게도this.grid(store getter)는 null이 아니며,__ob__ observer아이템. 이 때문에ifstatement는 truthy하며 새로운 사전 설정을 생성하지 않습니다.

여기서 응용 프로그램의 작업 예를 만들었습니다.

https://codesandbox.io/s/vuetify-vuex-and-vuerouter-h6yqu

MapSettings에서 설정을 정의할 수 있습니다.vue와 그gridmapSetup의 상태를 다음과 같이 설정해야 합니다.nullMapSetup.vue로 리다이렉트 한 후 그리드가 표시되지 않습니다.this.grid돌아온다__ob__ observernull 대신.

어떻게 하면 고칠 수 있죠?

[MutationTypes.RESET_MAP_SETUP]: state => {
    state.grid = [];
}

그리드를 리셋할 때 그리드를 null이 아닌 빈 배열로 설정하기 때문에 마운트된 훅에서 null이 되지 않습니다.

언급URL : https://stackoverflow.com/questions/56445044/store-getter-returns-observer-object-instead-of-null

반응형