반응형
계산된 속성에서 오류가 반환되는 이유
사용하고 있다.Vuex
, 안에Getter Foo function
배열 내에서 두 개의 값을 반환하는 중:
return ["Try Again"]
또는return ["Data result", data]
계산된 결과, 나는array length
그리고 결과에 따라 되돌아온다.
computed:{
Foo: function(){
const getFoo = this.$store.getters.Foo;
if(getFoo.length === 1) {
this.existFoo = false
return getFoo[0]
}
this.existFoo = true
return getFoo
}
}
하지만 나는 이런 실수를 하고 있다. 심지어 다른 글을 읽어도 나는 그것을 해결할 수 없다.
34:9 오류 "Foo" 계산 속성 vue/비부작용 계산 속성에서 예기치 않은 부작용
37:7 오류 "Foo" 계산 속성 vue/비부작용 계산 속성에서 예기치 않은 부작용
당신은 컴퓨터 사용의 상태를 변경할 수 없다.다음 대신 다른 계산된 컴퓨터를 사용해 보십시오.existFoo
computed:{
Foo(){
if(this.$store.getters.Foo.length === 1) {
return this.$store.getters.Foo[0]
}
return this.$store.getters.Foo
},
existFoo(){
return this.$store.getters.Foo.length > 1
}
}
이제 제거하십시오.existFoo
로부터state
감시자를 사용하여 저장 값을 감시하고 로컬 변수를 설정할 수 있다.
computed: {
getFooFromStore() {
return this.$store.getters.Foo
}
}
watch: {
getFooFromStore: function() {
this.existFoo = this.getFooFromStore[0] ? false : true;
}
}
참조URL: https://stackoverflow.com/questions/66235491/why-am-i-getting-error-return-in-computed-property
반응형
'programing' 카테고리의 다른 글
Ubuntu에서 pip을 통해 python3 버전의 패키지를 설치하는 방법? (0) | 2022.03.14 |
---|---|
RouteEnter 후크 전에 vue-router 내의 다른 URL로 리디렉션하는 방법? (0) | 2022.03.14 |
ResactJS에서 Hover하는 방법 - onMouseHouse 빠른 Hover 동안 등록되지 않음 (0) | 2022.03.14 |
전자 메일 클라이언트 시작 및 열기 방법반응JS (0) | 2022.03.14 |
Vuetify에서 사용자 지정 테마를 사용하고 색 변수를 구성 요소에 전달 (0) | 2022.03.14 |