闲来无事搞了个 Vue 的 babel 插件,可以让 Vue 的 jsx 语法更加接近 React

查看 21|回复 2
作者:apades   
因为有点受不了 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({
    addCount() {
      innerCount.value++
    },
  })
  if(!props.children) return no children
  return (
   
      {props.header(innerCount.value)}
       innerCount.value++}>
        {props.name} count: {innerCount.value}
      
      {props.children}
   
  )
}
项目目前就 preview 版本,还不算稳定
https://github.com/apades/make-vue-coding-more-like-react

Vue, jsx, plugin

shintendo   
className 也有好好还原吗
apades
OP
  
@shintendo 没,className 和 class 我感觉也没差
您需要登录后才可以回帖 登录 | 立即注册

返回顶部