@@ -12,6 +12,8 @@ Do the same work like [vue-class-component](https://github.com/vuejs/vue-class-c
12
12
13
13
# Finished
14
14
15
+ ### Basic
16
+
15
17
``` typescript
16
18
import {
17
19
Component ,
@@ -23,7 +25,7 @@ import {
23
25
Base ,
24
26
} from " vue-facing-decorator" ;
25
27
import AnotherComponent from " ./AnotherComponent.vue" ;
26
- // super class, DO NOT SUPPORT ANY DECORATOR now
28
+ // super class, See [extends section](#Extends)
27
29
class Sup extends Base {
28
30
// reactivity super property
29
31
supProperty = " supProperty" ;
@@ -48,6 +50,14 @@ class Sup extends Base {
48
50
// OPTION, components
49
51
components: {
50
52
AnotherComponent ,
53
+ },
54
+ // OPTION, inheritAttrs
55
+ inheritAttrs:true ,
56
+ // OPTION, expose
57
+ expose:[],
58
+ // OPTION, directives
59
+ directives:{
60
+
51
61
},
52
62
// OPTION, use modifier to modify component option built by vue-facing-decorator
53
63
modifier : (option : any ) => {
@@ -232,4 +242,95 @@ export default defineComponent({
232
242
);
233
243
},
234
244
});
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
+
235
336
```
0 commit comments