- 1.10 props methods inject computed合并
1.10 props methods inject computed合并
源码的设计将props.methods,inject,computed归结为一类,他们的配置策略一致,简单概括就是,如果父类不存在选项,则返回子类选项,子类父类都存在时,用子类选项去覆盖父类选项。
// 其他选项合并策略strats.props =strats.methods =strats.inject =strats.computed = function (parentVal,childVal,vm,key) {if (childVal && "development" !== 'production') {assertObjectType(key, childVal, vm);}if (!parentVal) { return childVal } // 父类不存在该选项,则返回子类的选项var ret = Object.create(null);extend(ret, parentVal); //if (childVal) {// 子类选项会覆盖父类选项的值extend(ret, childVal); }return ret};
