Skip to content

Commit c22a7a0

Browse files
committed
render, readme
1 parent d1ba63b commit c22a7a0

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

readme.md

+66
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Welcome to suggest and contribute. Message me on github.
2222

2323
* [Basic](#basic)
2424
* [Extends](#extends)
25+
* [Tsx render](#tsx-render)
2526

2627
### Basic
2728

@@ -344,4 +345,69 @@ export default defineComponent({
344345
}
345346
})
346347

348+
```
349+
350+
### Tsx render
351+
352+
```tsx
353+
//in Comp.render.tsx
354+
import type Comp from './Comp'
355+
356+
export default function render(this: Comp) {
357+
return <div onClick={this.onClick}>Tsx render {this.number}</div>
358+
}
359+
360+
//in Comp.ts
361+
import {
362+
Component,
363+
Base,
364+
} from 'vue-facing-decorator'
365+
import render from './Comp.render'
366+
367+
@Component({
368+
render
369+
})
370+
export default class Comp extends Base {
371+
number = 1
372+
onClick() {
373+
this.number++
374+
}
375+
}
376+
377+
//in parent component
378+
import {
379+
Component,
380+
Base,
381+
} from 'vue-facing-decorator';
382+
import Comp from "./Comp"
383+
384+
@Component({
385+
components:{
386+
Comp
387+
}
388+
})
389+
export default class ParentComponent extends Base {
390+
391+
}
392+
```
393+
394+
is euqal to
395+
396+
```typescript
397+
//in Comp.ts
398+
import { defineComponent } from "vue";
399+
import render from './Comp.render'
400+
export default defineComponent({
401+
render,
402+
data(){
403+
return {
404+
number:1
405+
}
406+
},
407+
methods:{
408+
onClick(){
409+
this.number++
410+
}
411+
}
412+
})
347413
```

src/component.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type ComponentOption = {
5555
directives?: Record<string, any>;
5656
inheritAttrs?: boolean;
5757
expose?: string[];
58+
render?: Function;
5859
modifier?: (raw: any) => any
5960
}
6061
type ComponentConsOption = Cons | ComponentOption
@@ -91,7 +92,9 @@ function ComponentStepWithOption(cons: Cons, arg: ComponentOption, extend?: any)
9192
if (arg.expose) {
9293
option.expose = arg.expose
9394
}
94-
95+
if (arg.render) {
96+
option.render = arg.render
97+
}
9598
if (arg.modifier) {
9699
option = arg.modifier(option)
97100
if (!option) {
@@ -107,12 +110,11 @@ export function ComponentBase(cons: Cons) {
107110
return cons
108111
}
109112

110-
export function Component(arg: Cons|ComponentOption) {
113+
export function Component(arg: Cons | ComponentOption) {
111114

112115
function extend(cons: Cons) {
113116
ComponentBase(cons)
114117
const slotPath = extendSlotPath(cons.prototype)
115-
116118
slotPath.forEach(proto => {
117119
const slot = obtainSlot(proto)
118120
if (!slot.inComponent) {

0 commit comments

Comments
 (0)