IT이야기

Mapstate를 사용하여 이 데이터를 매핑하는 방법

cyworld 2022. 5. 25. 22:19
반응형

Mapstate를 사용하여 이 데이터를 매핑하는 방법

데이터를 가져올 수 있다.this.$store.state.workermanage.staff.staff

하지만 어떻게 이 코드를...mapstate를 사용하여 교환할 수 있을까, 고마워.

persons: this.$store.state.workermanage.staff.staff

computed: {
  ...mapState({ persons: state => state.workermanage.staff.staff })
}

그리고 다음과 같이 사용하십시오.

{{ persons }}

중첩에 대한 게터 만들기staff저장되어 있는 것을 반대하다.

const store = new Vuex.Store({
  state: {
    workmanage: {
        staff: {
            staff: {

            } 
        }
    }
  },
  getters: {
    nestedStaff: state => {
      return state.workamage.staff.staff
    }
  }
})

구성 요소의 getter 사용:

import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters([
      'nestedStaff'
    ])
  }
}

그 후에, 당신은 사용할 수 있다.nestedStaff단순한 계산된 재산이었기 때문에

참조URL: https://stackoverflow.com/questions/61186412/how-to-use-mapstate-to-map-this-data

반응형