在什么场景下组件用 h 函数 或者 jsx #3931 #6945
Answered
by
Justineo
Miofly
asked this question in
Help/Questions
-
看很多开源组件库代码中有部分用到了 h 函数,按照理解 h 函数和 createVnode 差不多创建一个虚拟 dom,但是 h 函数的写法相比 jsx 麻烦很多,想了解直接用 jsx 替代 h 函数,从 jsx 转换成 vnode,这种在性能上有什么影响吗,或者说什么场景下组件用 h 函数或者 jsx |
Beta Was this translation helpful? Give feedback.
Answered by
Justineo
Oct 25, 2022
Replies: 2 comments 2 replies
-
JSX 需要编译工具链支持, |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Miofly
-
什么时候使用jsx,什么时候使用h,我个人觉得,如果在一个vue的组件中,有一个像是element的ElMessage的指令,他可以支持message是自定义的vnode,而此时,你可以新建一个组件文件,但是这里message的内容一般比较少,新建文件,显得有些繁琐,那么直接写h是不是方便很多,也不需要新建文件了,而且,这里也不能写jsx。除此之外,如果通用的情况下,我个人建议的是,如果内容很多,写jsx的可读性比h好很多 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSX 需要编译工具链支持,
h
函数是运行时的,直接用h
写 HyperScript 不需要编译。