Vue: 通过 vue-class-component 自定义方法不被 $ref 识别

创建于 2017-01-23  ·  3评论  ·  资料来源: vuejs/vue

大家好,

我收到这样的错误消息:

error TS2339: Property 'show' does not exist on type 'Element | Vue | Vue[] | Element[]'

它指向这样的一行:

this.$refs['myDialog'].show()

这个show是在 TypeScript 中使用 vue-class-component 实现的方法。 它在一个扩展 Vue 的类中。 我在这里找到了 ./types/vue.d.ts 中的行。

我想它应该使用这样的泛型进行修改:

readonly $refs: { [key: string]: [V extends Vue] | Element | Array<V extends Vue> | Array<Element>};

但仅仅这样做是行不通的。

有人知道怎么做吗?

谢谢!

最有用的评论

您要么需要转换它<YourComonent>this.$refs或 reify $refs
https://github.com/HerringtonDarkholme/av-ts/wiki/FAQ#2-property-reification

所有3条评论

您要么需要转换它<YourComonent>this.$refs或 reify $refs
https://github.com/HerringtonDarkholme/av-ts/wiki/FAQ#2-property-reification

你的描述不让我知道如何解决这个问题。 请逐步显示答案。

真的很困惑 ts+ vue

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

bdedardel picture bdedardel  ·  3评论

fergaldoyle picture fergaldoyle  ·  3评论

6pm picture 6pm  ·  3评论

hiendv picture hiendv  ·  3评论

paulpflug picture paulpflug  ·  3评论