在使用ts的过程中发现,父组件调用子组件方法的时候
this.$refs.chlid.fn()
发现vscode报错Property 'chlidMethod' does not exist on type 'Vue的情况,但是实际上运行效果完全没问题。
主要原因是 vscode会根据声明文件自动进行类型推断的,这里没法知道fn的类型
因此,如下即可
(this.$refs.chlid as any).fn()
在使用ts的过程中发现,父组件调用子组件方法的时候
this.$refs.chlid.fn()
发现vscode报错Property 'chlidMethod' does not exist on type 'Vue的情况,但是实际上运行效果完全没问题。
主要原因是 vscode会根据声明文件自动进行类型推断的,这里没法知道fn的类型
因此,如下即可
(this.$refs.chlid as any).fn()
本文标题:vue + typescript使用过程中报Property '
本文链接:https://www.haomeiwen.com/subject/lrcduktx.html
网友评论