programing

유형 스크립트가 포함된 Vue 플러그인이 null의 속성 '_init'을 읽을 수 없습니다.

prostudy 2022. 7. 4. 21:44
반응형

유형 스크립트가 포함된 Vue 플러그인이 null의 속성 '_init'을 읽을 수 없습니다.

재사용 가능한 몇 가지 구성 요소가 포함된 Vue 플러그인을 생성해야 합니다.TypeScript를 사용하여 만들고 싶습니다.내 파일이 있습니다.


컴포넌트/SampleButton을 선택합니다.표시하다

<template>
  <button>Sample button</button>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  name: 'sample-button',
});
</script>

메인

import SampleButton from './components/SampleButton.vue';

export {
  SampleButton,
};

export default {
  install(Vue: any, _options: object = {}): void {
    Vue.component(SampleButton.name, SampleButton);
  },
};


shims-vue.d.ts

declare module '*.vue' {
  import Vue from 'vue';

  export default Vue;
}


플러그인 구축은 성공했지만 앱에서 플러그인을 사용하려고 하면 다음과 같은 오류가 나타납니다.

import MyPlugin from 'my-plugin'

Vue.use(MyPlugin)

여기에 이미지 설명 입력

실수를 찾을 수 있도록 도와주세요:)

언급URL : https://stackoverflow.com/questions/58980982/vue-plugin-with-typescript-cannot-read-property-init-of-null

반응형