Skip to content

Commit 2eefcea

Browse files
committed
@component template
1 parent f1a5a19 commit 2eefcea

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

readme.md

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class Sup extends Base {
7373
//OPTION, directives
7474
directives:{
7575

76+
},
77+
//OPTION, template string, [NEED VUE FULL BUILD](https://vuejs.org/api/options-rendering.html#template).
78+
template:'<div></div>',
79+
//OPTION, render function
80+
render(){
81+
7682
},
7783
//OPTION, this will be assigned to vue option
7884
options: {
@@ -262,6 +268,10 @@ export default defineComponent({
262268
);
263269
},
264270
beforeRouteEnter() {},
271+
template:'<div></div>',
272+
render(){
273+
274+
}
265275
});
266276
```
267277

src/component.ts

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent,ComponentCustomOptions } 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,7 +57,8 @@ type ComponentOption = {
5757
expose?: string[];
5858
render?: Function;
5959
modifier?: (raw: any) => any
60-
options?:ComponentCustomOptions&Record<string,any>
60+
options?: ComponentCustomOptions & Record<string, any>
61+
template?: string
6162
}
6263
type ComponentConsOption = Cons | ComponentOption
6364
function ComponentStep(cons: Cons, extend?: any) {
@@ -67,37 +68,23 @@ function ComponentStep(cons: Cons, extend?: any) {
6768
function ComponentStepWithOption(cons: Cons, arg: ComponentOption, extend?: any): any {
6869
let option = ComponentOption(cons, extend)
6970
const slot = obtainSlot(cons.prototype)
70-
if (typeof arg.name !== 'undefined') {
71-
option.name = arg.name
72-
}
71+
72+
Object.keys(arg).reduce<Record<string, any>>((option, name: string) => {
73+
if (['options', 'modifier','emits'].includes(name)) {
74+
return option
75+
}
76+
option[name] = arg[name as keyof ComponentOption]
77+
return option
78+
}, option)
7379

7480
let emits = Array.from(slot.obtainMap('emits').keys())
7581
if (Array.isArray(arg.emits)) {
7682
emits = Array.from(new Set([...emits, ...arg.emits]))
7783
}
7884
option.emits = emits
7985

80-
81-
if (arg.components) {
82-
option.components = arg.components
83-
}
84-
if (arg.provide) {
85-
option.provide = arg.provide
86-
}
87-
if (arg.directives) {
88-
option.directives = arg.directives
89-
}
90-
if (arg.inheritAttrs) {
91-
option.inheritAttrs = arg.inheritAttrs
92-
}
93-
if (arg.expose) {
94-
option.expose = arg.expose
95-
}
96-
if (arg.render) {
97-
option.render = arg.render
98-
}
99-
if(arg.options){
100-
Object.assign(option,arg.options)
86+
if (arg.options) {
87+
Object.assign(option, arg.options)
10188
}
10289
if (arg.modifier) {
10390
option = arg.modifier(option)
@@ -115,7 +102,6 @@ export function ComponentBase(cons: Cons) {
115102
}
116103

117104
export function Component(arg: ComponentConsOption) {
118-
119105
function extend(cons: Cons) {
120106
ComponentBase(cons)
121107
const slotPath = extendSlotPath(cons.prototype)

test/component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const FullOptionOpt = {
3434
},
3535
options: {
3636
test: 'test value'
37-
}
37+
},
38+
template:'template string'
3839
}
3940

4041
@Component(FullOptionOpt)

0 commit comments

Comments
 (0)