ค้นหาเว็บไซต์

javascript - ปลั๊กอิน Vue กับ Typescript - ไม่สามารถอ่านคุณสมบัติ '_init' ของค่า null


ฉันจำเป็นต้องสร้างปลั๊กอิน Vue ที่มีคอมโพเนนต์ที่ใช้งานซ้ำได้หลายตัว ฉันต้องการสร้างสิ่งนี้โดยใช้ TypeScript นี่คือไฟล์ของฉัน:

components/SampleButton.vue

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

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

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

main.ts

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)

ช่วยฉันหาข้อผิดพลาดหน่อย :)

บทความที่เกี่ยวข้อง