Skip to content

Commit 9d5801a

Browse files
committed
readme
1 parent 6aed7ee commit 9d5801a

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed

readme.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Do the same work like [vue-class-component](https://github.com/vuejs/vue-class-c
1212

1313
# Finished
1414

15+
### Basic
16+
1517
```typescript
1618
import {
1719
Component,
@@ -23,7 +25,7 @@ import {
2325
Base,
2426
} from "vue-facing-decorator";
2527
import AnotherComponent from "./AnotherComponent.vue";
26-
//super class, DO NOT SUPPORT ANY DECORATOR now
28+
//super class, See [extends section](#Extends)
2729
class Sup extends Base {
2830
//reactivity super property
2931
supProperty = "supProperty";
@@ -48,6 +50,14 @@ class Sup extends Base {
4850
//OPTION, components
4951
components: {
5052
AnotherComponent,
53+
},
54+
//OPTION, inheritAttrs
55+
inheritAttrs:true,
56+
//OPTION, expose
57+
expose:[],
58+
//OPTION, directives
59+
directives:{
60+
5161
},
5262
//OPTION, use modifier to modify component option built by vue-facing-decorator
5363
modifier: (option: any) => {
@@ -232,4 +242,95 @@ export default defineComponent({
232242
);
233243
},
234244
});
245+
```
246+
247+
### Extends
248+
249+
```typescript
250+
import { Component, ComponentBase, Base } from 'vue-facing-decorator'
251+
//Comp1 super class
252+
class Comp1Sup extends Base {
253+
method1Sup() {
254+
return 'method1Sup value'
255+
}
256+
}
257+
/*
258+
Comp1 base component. To define a base component use `@ComponentBase` instead of `@Component`.
259+
Runtime will bundle Class `Comp1` and `Comp1Sup` to a vue option component.
260+
Methods of Comp1 will override `Comp1Sup`'s.
261+
Decorators can be only used on `@Component` and `@ComponentBase` classes. Comp1Sup don't accept any decorators.
262+
*/
263+
@ComponentBase
264+
class Comp1 extends Comp1Sup {
265+
method1Comp() {
266+
return 'method1Comp value'
267+
}
268+
}
269+
270+
class Comp2Sup extends Comp1 {
271+
method2Sup() {
272+
return 'method2Sup value'
273+
}
274+
}
275+
276+
277+
/*
278+
Similer to Comp1, runtime will bundle class `Comp2` and `Comp2Sup` into a vue option component.
279+
Bundled `Comp2` will extends bundled `Comp1` by vue `extends` option `{extends:Comp1}`
280+
*/
281+
@ComponentBase
282+
class Comp2 extends Comp2Sup {
283+
method2Comp() {
284+
return 'method2Comp value'
285+
}
286+
}
287+
288+
class Comp3Sup extends Comp2 {
289+
method3Sup() {
290+
return 'method3Sup value'
291+
}
292+
}
293+
294+
/*
295+
296+
(Comp3 -> Comp3Sup) vue extends (Comp2 -> Comp2Sup) vue extends (Comp1 -> Comp1Sup)
297+
298+
Class extends class by ES class extending stratge i.e. `Comp3 -> Comp3Sup` .
299+
300+
Vue component extends vue component by vue component exteding strategy i.e. `(Comp3 -> Comp3Sup) vue extends (Comp2 -> Comp2Sup)`
301+
302+
`Comp3` is a "Final Component" decorated by '@Component'.
303+
*/
304+
@Component
305+
export default class Comp3 extends Comp3Sup {
306+
method3Comp() {
307+
return 'method3Comp value'
308+
}
309+
}
310+
```
311+
312+
is euqal to
313+
314+
```typescript
315+
import { defineComponent } from 'vue';
316+
export default defineComponent({
317+
extends: {
318+
extends: {
319+
methods: {
320+
method1Comp() {
321+
return 'method1Comp value'
322+
}
323+
}
324+
},
325+
method2Comp() {
326+
return 'method2Comp value'
327+
}
328+
},
329+
methods: {
330+
method3Comp() {
331+
return 'method3Comp value'
332+
}
333+
}
334+
})
335+
235336
```

test/feature/extends.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,25 @@ describe('feature extends',
7272
})
7373
}
7474
)
75-
export default {}
75+
76+
77+
// import { defineComponent } from 'vue';
78+
// export default defineComponent({
79+
// extends: {
80+
// extends: {
81+
// methods: {
82+
// method1Comp() {
83+
// return 'method1Comp value'
84+
// }
85+
// }
86+
// },
87+
// method2Comp() {
88+
// return 'method2Comp value'
89+
// }
90+
// },
91+
// methods: {
92+
// method3Comp() {
93+
// return 'method3Comp value'
94+
// }
95+
// }
96+
// })

0 commit comments

Comments
 (0)