Skip to content

Commit cf1901e

Browse files
committed
文档: 更改readme
1 parent 4b95b0c commit cf1901e

File tree

1 file changed

+0
-131
lines changed

1 file changed

+0
-131
lines changed

README.md

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -38,137 +38,6 @@ yarn add vue3-oop
3838

3939
因为esbuild不支持装饰器的metadata属性,所以需要安装 [vite-plugin-ts](https://github.com/CarterLi/vite/tree/main/packages/plugin-vue-jsx#readme) 插件使用原始ts编译
4040

41-
### API
42-
43-
| 装饰器 | 描述 |
44-
| --- | --- |
45-
| Ref | 标记变量为响应式 |
46-
| Computed | 标记变量为计算属性 |
47-
| Hook | 标记生命周期触发的函数 |
48-
| Link | 相当于refs[key] |
49-
50-
2个基础类
51-
52-
1. 组件继承 `VueComponent`
53-
2. 服务继承 `VueService`
54-
55-
56-
### 组件编写
57-
58-
```tsx
59-
import {
60-
ComponentProps,
61-
Computed,
62-
Hook,
63-
Ref,
64-
VueComponent
65-
} from '@titanmatrix/vue3-class-component'
66-
import { ChildService } from './child.service'
67-
68-
/**
69-
* 组件属性
70-
*/
71-
interface ChildProps {
72-
/**
73-
* 尺寸
74-
*/
75-
size: number
76-
/**
77-
* 姓名
78-
*/
79-
name?: string
80-
}
81-
82-
export class Child extends VueComponent<ChildProps> {
83-
/**
84-
* vue描述的属性定义
85-
*/
86-
static defaultProps: ComponentProps<ChildProps> = {
87-
size: {
88-
type: Number,
89-
required: true,
90-
},
91-
name: String,
92-
}
93-
childService = new ChildService()
94-
@Ref() name = 'child'
95-
96-
@Computed()
97-
get nameUpper() {
98-
return this.name.toUpperCase()
99-
}
100-
101-
@Hook('Mounted')
102-
mounted() {
103-
console.log('mounted')
104-
}
105-
106-
@Link()
107-
root?: HTMLDivElement
108-
109-
constructor() {
110-
super()
111-
// watch 需要写在 constructor中
112-
watch(() => this.name, this.nameChange)
113-
}
114-
115-
nameChange = () => {
116-
console.log(this.name)
117-
}
118-
119-
render() {
120-
return (
121-
<div ref={'root'}>
122-
属性:{this.props.size}
123-
<h2>自有变量</h2>i am a {this.name}
124-
大写 {this.nameUpper}
125-
reactive 变量 {this.obj.age}
126-
<h3>service</h3>
127-
<button onClick={() => this.childService.add()}>+</button>
128-
{this.childService.count}
129-
<button onClick={() => this.childService.reduce()}>-</button>
130-
</div>
131-
)
132-
}
133-
}
134-
```
135-
136-
### 服务
137-
138-
通常服务是指很纯粹的业务逻辑,等价于vue3新提出的 `useFunction`, 例子如下:
139-
140-
```typescript
141-
import { Hook, Ref, VueService, WatchEffect } from '@titanmatrix/vue3-class-component'
142-
import { InjectionKey } from 'vue'
143-
144-
/**
145-
* 服务需要继承 VueService
146-
*/
147-
export class ChildService extends VueService {
148-
// 如果有此属性将自动 provide
149-
static ProviderKey: InjectionKey<ChildService> = Symbol()
150-
/**
151-
* 正常变量定义,成为响应式变量
152-
*/
153-
@Ref() count = 1
154-
155-
countChange() {
156-
console.log(this.count)
157-
}
158-
@Hook('BeforeUnmount')
159-
destroy() {
160-
console.log('做一些清理工作')
161-
}
162-
163-
add() {
164-
this.count++
165-
}
166-
reduce() {
167-
this.count--
168-
}
169-
}
170-
```
171-
17241
### 依赖注入
17342

17443
Angular文档

0 commit comments

Comments
 (0)