Skip to content

Commit 03f51dd

Browse files
committed
refactor: 重构 tsx 组件
1 parent 4243ef1 commit 03f51dd

File tree

13 files changed

+257
-652
lines changed

13 files changed

+257
-652
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ your-project/
3131
pnpm add vue @vueuse/core
3232

3333
# 开发依赖,以 Vite 为例
34-
pnpm add vue-component-type-helpers type-fest typescript vite @vitejs/plugin-vue @vitejs/plugin-vue-jsx -D
34+
pnpm add vue-component-type-helpers type-fest typescript vite @vitejs/plugin-vue -D
3535

3636
```
3737

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"@types/archiver": "^7.0.0",
7070
"@types/node": "^22.16.0",
7171
"@vitejs/plugin-vue": "^6.0.1",
72-
"@vitejs/plugin-vue-jsx": "^5.1.1",
7372
"@vue/tsconfig": "^0.8.1",
7473
"@vueuse/core": "^14.0.0",
7574
"archiver": "^7.0.1",
@@ -87,7 +86,6 @@
8786
"unplugin-raw": "^0.6.3",
8887
"unplugin-vue": "^7.0.3",
8988
"unplugin-vue-components": "^30.0.0",
90-
"unplugin-vue-jsx": "^0.8.1",
9189
"unplugin-vue-router": "^0.16.0",
9290
"vite": "npm:rolldown-vite@^7.1.19",
9391
"vitest": "^4.0.10",

playground/src/App.vue

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<script setup lang="tsx">
1+
<script setup lang="ts">
22
import type { FunctionalComponent } from 'vue'
33
import type { RouteRecordRaw } from 'vue-router'
4-
import { ElSubMenu } from 'element-plus'
4+
import { ElMenuItem, ElSubMenu } from 'element-plus'
55
import { camelize } from 'vue'
66
import { routes } from 'vue-router/auto-routes'
77
@@ -16,25 +16,23 @@ const ReMenuItem: FunctionalComponent<{
1616
}> = ({ route: propRoute, parentPath }) => {
1717
const fullPath = `${parentPath}${parentPath ? '/' : ''}${propRoute.path}`
1818
if (propRoute.children?.length) {
19-
return (
20-
<ElSubMenu index={fullPath}>
21-
{{
22-
title: () => getMenuTitle(propRoute.path),
23-
default: () =>
24-
propRoute.children!.map((route) => (
25-
<ReMenuItem
26-
key={`${fullPath}/${route.path}`}
27-
route={route}
28-
parentPath={fullPath}
29-
/>
30-
)),
31-
}}
32-
</ElSubMenu>
19+
return h(
20+
ElSubMenu,
21+
{ index: fullPath },
22+
{
23+
title: () => getMenuTitle(propRoute.path),
24+
default: () =>
25+
propRoute.children!.map((route) =>
26+
h(ReMenuItem, {
27+
key: `${fullPath}/${route.path}`,
28+
route,
29+
parentPath: fullPath,
30+
}),
31+
),
32+
},
3333
)
3434
}
35-
return (
36-
<ElMenuItem index={fullPath}>{getMenuTitle(propRoute.path)}</ElMenuItem>
37-
)
35+
return h(ElMenuItem, { index: fullPath }, () => getMenuTitle(propRoute.path))
3836
}
3937
4038
ReMenuItem.props = {

0 commit comments

Comments
 (0)