记VUE3+TS 获取组件类型的方法踩坑
获取组件类型的方法
const AccountRef = ref<InstanceType<typeof LoginAccount>>()
遇到的坑:typeof LoginAccount一直报红线提示错误
LoginAction: () => vo...' provides no match for the signature 'new (...args: any): any'.
问题原因:
使用的是webstorm codeing,通过webstorm自带右键新建vue文件,创建出来的文件是不带defineComponent的,所以导致上述的一直报红线
<script lang="ts">
export default {
}
</script>
解决办法:引用defineComponent
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({//注意这里的这个小括号不能漏
})
</script>