Vue3 如何根据 defineComponent 获取实例的类型?

Vue3 如何根据 defineComponent 获取实例的类型?

// vue.d.ts

declare module '*.vue' {

import {Component} from '@vue/runtime-core';

const content: Component;

export default content;

}

// MyComponent.vue

<template><div>...</div></template>

<script lang="ts" src="./MyComponent.ts"></script>

// MyComponent.ts

import {defineComponent, ref} from 'vue';

export default defineComponent({

setup() {

const foo = ref(1);

return {foo};

}

});

// foo.ts

import MyComponent from './MyComponent.vue';

import MyComponentDefine from './MyComponent.ts';

import {createApp} from 'vue';

const app = createApp(MyComponent);

const vm = app.mount('#foo') as <?>; // <-- 如何根据 MyComponentDefine 获取类型?

console.log(vm.foo);

以上是 Vue3 如何根据 defineComponent 获取实例的类型? 的全部内容, 来源链接: utcz.com/p/935379.html

回到顶部