programing

VueStoreFront: 커스텀 모듈: 상태는 갱신되지만 컴포넌트는 갱신되지 않음

bestcode 2022. 7. 11. 22:14
반응형

VueStoreFront: 커스텀 모듈: 상태는 갱신되지만 컴포넌트는 갱신되지 않음

"에서 데이터를 가져오는 커스텀 모듈을 만들고 있습니다.afterRegistration" 를 눌러 결과를 저장소에 저장합니다.

상태가 업데이트되었지만(VueDevTools에서 업데이트를 볼 수 있음) 구성 요소는 여전히 기본 상태입니다.내가 뭘 잘못하고 있지?

// afterRegistration
export function afterRegistration ({Vue, config, store, isServer}) {
  store.dispatch(${KEY}/isVisible)
}

// component
export default {
  name: 'Test',
  components: { Fragment },
  props: {
   …
  },
  computed: {
    isVisible: el => el.$store.getters['myModule/simpleTest']
  }
}

당신은 반응성을 잃었어요.의 초기값을 설정합니다.simpleTest(문맥에서 보면) 당신이 좋아하는 것에 대한 상태상의 반대입니다.Boolean초기 상태가 아닌 경우 이 필드에 getter 또는 setter는 없습니다.

네, 비동기 로더로 디스패치를 해야 한다는 것을 알았습니다.

// afterRegistration
export function afterRegistration ({Vue, config, store, isServer}) {
  AsyncDataLoader.push({
   execute: ({ route, store, context }) => {
    return new Promise ((resolve, reject) => {
      store.dispatch(`${KEY}/getInlineTranslationConfig`)
        .then(() => resolve(null))
    })
  }
})

이제 됐다!

언급URL : https://stackoverflow.com/questions/57025377/vuestorefront-custom-module-state-is-updated-component-not

반응형