반응형
Vuex 및 vuex가 인수를 사용하는 getter
저는 Vue와 Vuex를 기반으로 한 작은 앱을 가지고 있습니다.그런 것들이 있는 테이블일 뿐이야
<div class='items'>
<div v-for='item in items'>
<span> {{ item.name }} </span>
<router-link :to='"update/" + item.id'>Edit</router-link>
</div>
</div>
항목 배열은 Getter를 사용하여 Vuex 상태에서 로드됩니다.문제는 '편집' 버튼을 누르면 다른 페이지로 리다이렉트된다는 것입니다.이 페이지에는 이와 같은 기능이 있습니다.
computed() {
item() {
return this.$store.getters.get_item(this.$route.params.id)
}
}
일반적으로 동작합니다(이것 대신 몇 가지 숫자를 전달하여 테스트했습니다).$route.params.id")는 아니지만, 이유는 무엇입니까?오류도 없고 아무것도 없습니다.어레이만 비어 있습니다.
get_item 함수
getters: {
get_item: (state) => (index) => {
return state.items.filter((item) => {
return item.id === index
}
}
}
정의하고 있다computed
함수로 사용할 수 있습니다.대신 시도:
computed: {
item() {
return this.$store.getters.get_item(this.$route.params.id)
}
}
언급URL : https://stackoverflow.com/questions/47455303/vuex-and-vuex-getters-with-arguments
반응형
'programing' 카테고리의 다른 글
Win32 - C 코드에서 역추적 (0) | 2022.08.09 |
---|---|
생성된 vuejs 구성 요소가 먼저 데이터가 로드되기를 기다립니다. (0) | 2022.08.09 |
Vuex 저장소 개체에서 계산된 속성이 업데이트되지 않음 (0) | 2022.07.21 |
express.body get 메서드가 req.body 값을 가져올 수 없습니다. (0) | 2022.07.21 |
Spring Cache @Cacheable - 같은 빈의 다른 메서드에서 호출 중 작동하지 않음 (0) | 2022.07.21 |