在什么场景下组件用 h 函数 或者 jsx #3931
-
看组件代码中有部分用到了 h 函数,按照理解 h 函数和 createVnode 差不多创建一个虚拟 dom,但是 h 函数的写法相比 jsx 麻烦很多,想了解直接用 jsx 替代 h 函数,从 jsx 转换成 vnode,这种在性能上有什么影响吗,或者说什么场景下组件用 h 函数或者 jsx |
Beta Was this translation helpful? Give feedback.
Answered by
XieZongChen
Oct 25, 2022
Replies: 1 comment
-
两者性能基本没有差距。jsx 更方便书写 template,且对于维护者来说几乎没有难度曲线。在部分场景(比如重逻辑且基本没有 template)下 jsx 可能没有 h 函数简洁,所以会用到 h 函数。而组件示例中使用 h 函数只是因为其不用做任何配置,以免误导不会配置 jsx 的用户。 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
XieZongChen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
两者性能基本没有差距。jsx 更方便书写 template,且对于维护者来说几乎没有难度曲线。在部分场景(比如重逻辑且基本没有 template)下 jsx 可能没有 h 函数简洁,所以会用到 h 函数。而组件示例中使用 h 函数只是因为其不用做任何配置,以免误导不会配置 jsx 的用户。