반응형
vuex를 사용하여 어레이 상태를 제어하는 방법은 무엇입니까?
vuex로 상태 배열을 읽고 싶습니다.
하지만 그것은
"TypeError: 정의되지 않은 속성 '0'을 읽을 수 없습니다."
[0] 오류가 발생한 것 같습니다.
아래에 몇 가지 코드가 있습니다.
// the code of index.vue
<template>
<div><p>{{ rectangles[0].x }}</p></div>
</template>
<script>
export default {
computed: {
rectangles () {
return this.$store.state.rectangles
}
},
}
</script>
여기는 vuex의 가게입니다.
export default {
state: {
rectangles: [
{
x: 150,
y: 100,
width: 100,
height: 100,
fill: "red",
name: "rect1",
draggable: true
},
{
x: 150,
y: 150,
width: 100,
height: 100,
fill: "green",
name: "rect2",
draggable: true
}
],
},
computed: {
rectangles () {
return this.$store.rectangles
}
},
그래야 한다
computed: {
rectangles () {
return this.$store.state.rectangles
}
},
하지만 가장 좋은 방법은 게터를 사용하는 것입니다(링크: https://vuex.vuejs.org/guide/getters.html ).
언급URL : https://stackoverflow.com/questions/54576954/how-to-control-array-state-with-vuex
반응형
'sourcecode' 카테고리의 다른 글
웹 배포 작업에 실패했습니다.('Microsoft'의 이니셜라이저입니다.웹, 배포.'배포 관리자'에서 예외를 발생시켰습니다.) (0) | 2023.07.13 |
---|---|
@Input()에 기반한 Angular 2 동적 종속성 주입 (0) | 2023.07.13 |
새 Firebase 콘솔에서 데이터베이스 및 스토리지 사용량을 확인하는 방법 (0) | 2023.07.13 |
IntelliJ IDEA 엔드포인트 탭을 표시하지 않음: "응용 프로그램 JMX 서비스 URL을 검색하지 못했습니다." (0) | 2023.07.13 |
Mongoose findOneAndUpdate 및 uversert에서 오류 및 영향을 받는 문서를 반환하지 않습니다. (0) | 2023.07.08 |