关于 Vue 3 + TypeScript 和 Augmenting-Types-for-Use-with-Plugins 的问题 [英] Question about Vue 3 + TypeScript and Augmenting-Types-for-Use-with-Plugins

查看:22
本文介绍了关于 Vue 3 + TypeScript 和 Augmenting-Types-for-Use-with-Plugins 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道应该如何使用 Vue3 和 TypeScript 实现类型增强的工作示例?我一直在尝试遵循 Vue2 文档,在 Vue3 中使用相同的文档但没有成功,并且在过去 3 个小时的搜索中没有任何结果.

vue-class-component 模块中的 Vue 对象似乎应该增加才能工作,但是如何?

我的实现类似于以下:

有什么建议吗?

https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins

import { App, Plugin } from vue";导出接口 IHelloModule {sayHello: (name: string) =>细绳;}export const helloPlugin: Plugin = (app: App, options) =>{const helloModule:IHelloModule = {sayHello:函数(名称:字符串){return `你好 ${name}`;}};app.provide("$hello", helloModule);};

import { Vue } from 'vue-class-component';import { IHelloModule } from "@/hello";声明模块vue/types/vue"{界面 Vue {$hello: IHelloModule;}}声明模块vue/types/vue"{接口 VueConstructor {$auth: IHelloModule;}}