Доработка vueComponent, теперь понимает иерархию классов

This commit is contained in:
Book Pauk
2022-10-21 20:18:32 +07:00
parent cd72de5014
commit 93634b1137

View File

@@ -17,7 +17,7 @@ export default function(componentClass) {
}
}
} else if (prop === '_props') {
comp['props'] = obj[prop];
comp.props = obj[prop];
}
} else {//usual prop
data[prop] = obj[prop];
@@ -26,10 +26,12 @@ export default function(componentClass) {
comp.data = () => _.cloneDeep(data);
//methods
const classProto = Object.getPrototypeOf(obj);
const classMethods = Object.getOwnPropertyNames(classProto);
const methods = {};
const computed = {};
let classProto = Object.getPrototypeOf(obj);
while (classProto) {
const classMethods = Object.getOwnPropertyNames(classProto);
for (const method of classMethods) {
const desc = Object.getOwnPropertyDescriptor(classProto, method);
if (desc.get) {//has getter, computed
@@ -44,6 +46,9 @@ export default function(componentClass) {
methods[method] = obj[method];
}
}
classProto = Object.getPrototypeOf(classProto);
}
comp.methods = methods;
comp.computed = computed;