Доработка vueComponent, теперь понимает иерархию классов
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user