[英]VSCode(Vetur) does not recognize customized Vue property in component
I've mounted a plugin on Vue in a main.ts file, declared its type in a plugin.d.ts file, then used it in a component.vue file.我在 Vue 上的 main.ts 文件中安装了一个插件,在 plugin.d.ts 文件中声明了它的类型,然后在 component.vue 文件中使用它。 The compilation works fine, but VSCode intellisense still tells me this property does not exist.
编译工作正常,但 VSCode 智能感知仍然告诉我这个属性不存在。 Am I missing anything?
我错过了什么吗? Here are the codes.
这是代码。
//plugin.ts
import Vue as _Vue from 'vue'
export class Plugin {
someFunc() { //do something }
}
const plugin = new Plugin()
export default function myPlugin(Vue: typeof _Vue) {
Vue.prototye.$plugin = plugin
}
and for declaration,和声明,
//plugin.d.ts
import { Plugin } from './plugin'
declare module 'vue/types/vue' {
interface Vue {
$plugin: Plugin
}
}
then I mount it in an entry point,然后我将它安装在一个入口点,
//main.ts
import Vue from 'vue'
import plugin from './plugin'
Vue.use(plugin)
finally, I want to use the plugin in a component,最后,我想在组件中使用插件,
//component.vue
import { Component, Vue } from 'vue-proprety-decorator'
@Component
export default class MyComponnent extends Vue {
func() {
this.$plugin.someFunc()
}
}
The compilation shows no problem, but intellisense tells me "Property '$plugin' does not exist on type 'MyComponent'."编译显示没有问题,但智能感知告诉我“类型 'MyComponent' 上不存在属性 '$plugin'。” and autocompletion does not work.
并且自动完成不起作用。
Did I do anything wrong?我做错什么了吗?
Try to change the name of the type definition from plugin.d.ts to types.d.ts.尝试将类型定义的名称从 plugin.d.ts 更改为 types.d.ts。 That did the trick for me.
这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.