Skip to content

Commit bd9b90c

Browse files
committed
component options
1 parent 19050b3 commit bd9b90c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Comp3Sup extends Comp2 {
307307
308308
(Comp3 -> Comp3Sup) vue extends (Comp2 -> Comp2Sup) vue extends (Comp1 -> Comp1Sup)
309309
310-
Class extends class by ES class extending stratge i.e. `Comp3 -> Comp3Sup` .
310+
Class extends class by ES class extending strategy i.e. `Comp3 -> Comp3Sup` .
311311
312312
Vue component extends vue component by vue component exteding strategy i.e. `(Comp3 -> Comp3Sup) vue extends (Comp2 -> Comp2Sup)`
313313
@@ -334,8 +334,10 @@ export default defineComponent({
334334
}
335335
}
336336
},
337-
method2Comp() {
338-
return 'method2Comp value'
337+
methods: {
338+
method2Comp() {
339+
return 'method2Comp value'
340+
}
339341
}
340342
},
341343
methods: {

src/component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent } from 'vue';
1+
import { defineComponent,ComponentCustomOptions } from 'vue';
22
import { obtainSlot, extendSlotPath } from './utils'
33
import { build as optionComputed } from './option/computed'
44
import { build as optionData } from './option/data'
@@ -57,6 +57,7 @@ type ComponentOption = {
5757
expose?: string[];
5858
render?: Function;
5959
modifier?: (raw: any) => any
60+
options?:ComponentCustomOptions&Record<string,any>
6061
}
6162
type ComponentConsOption = Cons | ComponentOption
6263
function ComponentStep(cons: Cons, extend?: any) {
@@ -95,6 +96,9 @@ function ComponentStepWithOption(cons: Cons, arg: ComponentOption, extend?: any)
9596
if (arg.render) {
9697
option.render = arg.render
9798
}
99+
if(arg.options){
100+
Object.assign(option,arg.options)
101+
}
98102
if (arg.modifier) {
99103
option = arg.modifier(option)
100104
if (!option) {
@@ -110,7 +114,7 @@ export function ComponentBase(cons: Cons) {
110114
return cons
111115
}
112116

113-
export function Component(arg: Cons | ComponentOption) {
117+
export function Component(arg: ComponentConsOption) {
114118

115119
function extend(cons: Cons) {
116120
ComponentBase(cons)

test/component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const FullOptionOpt = {
3131
},
3232
render() {
3333
return 'render value'
34+
},
35+
options: {
36+
test: 'test value'
3437
}
3538
}
3639

@@ -62,6 +65,9 @@ describe('Component',
6265
case 'render':
6366
expect('render value').to.equal(FullOptionContext[key]())
6467
break;
68+
case 'options':
69+
expect(opt.test).to.equal(FullOptionContext['test'])
70+
break;
6571
case 'modifier':
6672
return;
6773
default:

0 commit comments

Comments
 (0)