【发布时间】:2025-12-12 20:05:01
【问题描述】:
我正在为我的 vue 指令打字,但我似乎找不到我应该为 Vue 安装功能使用什么类型。
使用install(Vue: any): void 似乎有点奇怪。
我尝试过导入Vue,然后使用install(Vue: Vue),但是会抛出一个错误,Vue 上没有.directive,这也很奇怪。
我应该如何输入安装函数? Vue 类型是否应该在这里工作?我在这里遗漏了什么,或者Vue 遗漏了什么?
import { DirectiveOptions } from "vue"
const directive: DirectiveOptions = {
bind(elem, bind, vn) {
console.log('bound')
}
};
export default {
install(Vue: any): void { // what types should be used here?
Vue.directive("do-stuff", directive);
}
};
【问题讨论】:
标签: typescript vue.js vuejs2 typescript-typings vue-directives