Skip to content

Commit b1ebfde

Browse files
committed
refactor: 增加示例
1 parent 6f63962 commit b1ebfde

22 files changed

+413
-52
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"docs:preview": "vitepress preview docs",
5959
"test:dev": "vitest --coverage",
6060
"test": "vitest run --coverage",
61-
"postinstall": "simple-git-hooks"
61+
"postinstall": "simple-git-hooks",
62+
"demo:dev": "pnpm -C playground dev"
6263
},
6364
"commitlint": {
6465
"extends": [

playground/global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

example/index.html renamed to playground/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</head>
88
<body>
99
<div id="app"></div>
10-
<script type="module" src="/example/main.tsx"></script>
10+
<script type="module" src="/src/main.tsx"></script>
1111
</body>
1212
</html>

playground/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "playground",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite"
8+
},
9+
"dependencies": {
10+
"@abraham/reflection": "^0.12.0",
11+
"injection-js": "^2.4.0",
12+
"vue": "^3.5.13",
13+
"vue-router": "^4.5.0",
14+
"vue3-oop": "workspace:*",
15+
"ant-design-vue": "^4.2.6",
16+
"tslib": "^2.8.1"
17+
},
18+
"devDependencies": {
19+
"vite": "^6.2.4",
20+
"typescript": "^5.8.2",
21+
"vite-plugin-tsconfig-paths": "^1.4.1",
22+
"@vue3-oop/plugin-vue-jsx": "^1.4.6"
23+
}
24+
}
File renamed without changes.

example/module/basic/simple-component/index.view.tsx renamed to playground/src/module/basic/simple-component/index.view.tsx

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { defineComponent, useClassAndStyle } from 'vue3-oop'
2-
import { ClassAndStyleProps } from '@/type'
31
import { ref } from 'vue'
2+
import { defineComponent, useClassAndStyle, type ClassAndStyleProps } from 'vue3-oop'
43

54
// region 函数组件
65
export interface SimpleFuncComponentProps extends ClassAndStyleProps {
@@ -16,23 +15,18 @@ export interface SimpleStateComponentProps {
1615
initialValue?: number
1716
}
1817

19-
export const SimpleStateComponent = defineComponent(
20-
function SimpleStateComponent(props: SimpleStateComponentProps) {
21-
const classAndStyle = useClassAndStyle()
22-
const count = ref(props.initialValue || 0)
23-
return () => (
24-
<div {...classAndStyle}>
25-
<input type={'number'} v-model={count.value} />
26-
</div>
27-
)
28-
},
29-
)
18+
export const SimpleStateComponent = defineComponent(function SimpleStateComponent(props: SimpleStateComponentProps) {
19+
const classAndStyle = useClassAndStyle()
20+
const count = ref(props.initialValue || 0)
21+
return () => (
22+
<div {...classAndStyle}>
23+
<input type={'number'} v-model={count.value} />
24+
</div>
25+
)
26+
})
3027

3128
export const SimpleStateWithDefaultValueComponent = defineComponent(
32-
function SimpleStateWithDefaultValueComponent(
33-
props: SimpleStateComponentProps,
34-
{ attrs },
35-
) {
29+
function SimpleStateWithDefaultValueComponent(props: SimpleStateComponentProps, { attrs }) {
3630
const classAndStyle = useClassAndStyle()
3731
const count = ref(props.initialValue || 0)
3832
return () => {
@@ -68,9 +62,7 @@ const SimpleComponent = defineComponent(() => {
6862
<h3>函数组件</h3>
6963
<SimpleFuncComponent count={20}></SimpleFuncComponent>
7064
<SimpleStateComponent initialValue={10}></SimpleStateComponent>
71-
<button onClick={() => (init.value = init.value ? undefined : 10)}>
72-
切换默认值
73-
</button>
65+
<button onClick={() => (init.value = init.value ? undefined : 10)}>切换默认值</button>
7466
<SimpleStateWithDefaultValueComponent
7567
class={'aaaa'}
7668
initialValue={init.value}
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { RouteRecordRaw } from 'vue-router'
22

33
// 自动收集子模块的路由
4-
const moduleRoutes = import.meta.globEager('../module/**/*.router.ts')
4+
const moduleRoutes = import.meta.glob('../module/**/*.router.ts', {
5+
eager: true,
6+
})
57

68
export const routes: RouteRecordRaw[] = Reflect.ownKeys(moduleRoutes)
7-
.map((k) => (moduleRoutes[k as string] as any).default as RouteRecordRaw)
9+
.map(k => (moduleRoutes[k as string] as any).default as RouteRecordRaw)
810
.filter(Boolean)
File renamed without changes.

playground/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"target": "ESNext",
5+
"baseUrl": ".",
6+
"paths": {
7+
"@/*": ["src/*"]
8+
}
9+
}
10+
}

playground/vite.config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import vueJsx from '@vue3-oop/plugin-vue-jsx'
2+
import { defineConfig } from 'vite'
3+
4+
export default defineConfig({
5+
plugins: [vueJsx()],
6+
})

0 commit comments

Comments
 (0)