[bugfix] Functional component inherit context (#2686)

This commit is contained in:
neverland 2019-02-05 12:04:34 +08:00 committed by GitHub
parent b896113ad6
commit ef38458a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -22,10 +22,12 @@ const prefix = (name, mods) => {
}
const ret = {};
mods &&
if (mods) {
Object.keys(mods).forEach(key => {
ret[name + MODS + key] = mods[key];
});
}
return ret;
};

View File

@ -30,15 +30,21 @@ function install(Vue) {
Vue.component(camelize(`-${name}`), this);
}
const inheritKey = ['style', 'class', 'nativeOn', 'directives', 'staticClass', 'staticStyle'];
const mapInheritKey = { nativeOn: 'on' };
function functional(sfc) {
const { render } = sfc;
sfc.functional = true;
sfc.render = (h, context) =>
render(h, context, {
style: context.data.style,
class: context.data.class,
staticClass: context.data.staticClass
});
sfc.render = (h, context) => {
const inherit = inheritKey.reduce((obj, key) => {
if (context.data[key]) {
obj[mapInheritKey[key] || key] = context.data[key];
}
return obj;
}, {});
return render(h, context, inherit);
};
}
export default name => (sfc, isFunctional) => {