vue3中 defineComponent 认识


官网解释

从实现上看,defineComponent 只返回传递给它的对象。但是,就类型而言,返回的值有一个合成类型的构造函数,用于手动渲染函数、TSX 和 IDE 工具支持。

官网示例

 

我在自己使用发现的

在单组件中时,

1、不用 defineComponent

会发现,setup中 props的 ts 类型为 any, 即:没有获取到 msg: {  },这个类型

2、结合 defineComponent

 

 会发现,setup中 props的 ts 类型为 找到类型,且 readonly

目前这个api还不是很6,可以共同探讨。。。