반응형
형식 스크립트가 포함된 Vuex 4를 사용하는 유형 'ComponentPublicInstance'에 속성 '$store'가 없습니다.
vuex에서 타이프스크립트 및 vue를 사용하는 프로젝트가 있는데 VSCode에서 다음 오류가 발생했습니다.
Property '$store' does not exist on type 'ComponentPublicInstance<{}, {}, {}, { errors(): any; }, { eliminarError(error: string): void; }, EmitsOptions, {}, {}, false, ComponentOptionsBase<{}, {}, {}, { errors(): any; }, { eliminarError(error: string): void; }, ... 4 more ..., {}>>'
매뉴얼을 읽었더니 다음 내용으로 d.ts 파일을 추가해야 한다고 되어 있습니다.
// vuex.d.ts
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'
declare module '@vue/runtime-core' {
// declare your own store states
interface State {
count: number
}
// provide typings for `this.$store`
interface ComponentCustomProperties {
$store: Store<State>
}
}
하지만 VSCode는'ComponentCustomProperties' is defined but never used
그리고 내가 말한 첫 번째 에러가 아직 표시된다.
어떻게 하면 이 문제를 해결할 수 있을까요?
VSCode에서도 이 오류가 발생하여 해결되었습니다.
// vuex.d.ts
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'
declare module '@vue/runtime-core' {
// declare your own store states
interface State {
count: number
}
// provide typings for `this.$store`
interface ComponentCustomProperties {
$store: Store<State>
}
}
공식 문서에 따른 설정은 적용되지 않았습니다.VSCode를 재시작한 후, 드디어 적용되었습니다.
더하다/* eslint-disable */
shims-vuex.d.ts 파일의 맨 위로 이동
언급URL : https://stackoverflow.com/questions/65237129/property-store-does-not-exist-on-type-componentpublicinstance-using-vuex-4
반응형
'programing' 카테고리의 다른 글
쓰기 전용 포인터 유형 (0) | 2022.08.13 |
---|---|
Vue.js 2, WATCH "워처 "Your AccountState" 콜백 오류: "ReferenceError: 값이 정의되지 않았습니다." (0) | 2022.08.13 |
함수 이름 주위의 괄호는 무엇을 의미합니까? (0) | 2022.08.13 |
수동으로 마운트된 vue 구성 요소 내에서 vuex 사용 (0) | 2022.08.13 |
메서드 내 Vuejs 빌드/렌더 컴포넌트와 템플릿 출력 (0) | 2022.08.10 |