
因为有点受不了 React 的细分组件优化,想试试 Vue 的 jsx ,结果要自己定义 props + defineComponent 写法好麻烦,所以自己花了 2 个星期的时间去把 @vitejs/plugin-vue-jsx 魔改了下,使语法更接近 React 了
举个
import { effect, ref, type VNode } from 'vue' type Props = { name: string header: (count: number) => VNode children?: VNode } type Handler = { addCount: () => void } function ChildComp(props: Props) { const innerCount = ref(0) defineExpose<Handler>({ addCount() { innerCount.value++ }, }) if(!props.children) return <div>no children</div> return ( <> <div>{props.header(innerCount.value)}</div> <div OnClick={() => innerCount.value++}> {props.name} count: {innerCount.value} </div> {props.children} </> ) } 项目目前就 preview 版本,还不算稳定
1 deng565430 14 天前 为啥不直接用 react |
2 apades OP @deng565430 emmm 你这问题我都不知道怎么回答了,我主力就在 react 这,我上面也提了 react 自身的缺陷,就想换换口味。总不能用没啥生态的 solid 吧,vue 也算是有社区支持 jsx 的 |