[improvement] Sku: partial functional (#2756)

This commit is contained in:
neverland
2019-02-15 21:00:46 +08:00
committed by GitHub
parent 632cfbcf36
commit 880f574b9a
3 changed files with 88 additions and 90 deletions

View File

@@ -1,32 +1,33 @@
import { use } from '../../utils';
import { inherit } from '../../utils/functional';
import Button from '../../button';
const [sfc, bem] = use('sku-actions');
export default sfc({
props: {
buyText: String,
skuEventBus: Object,
showAddCartBtn: Boolean
},
function SkuActions(h, props, slots, ctx) {
const emit = name => () => {
props.skuEventBus.$emit(name);
};
render(h) {
const emit = name => () => {
this.skuEventBus.$emit(name);
};
return (
<div class={bem()} {...inherit(ctx)}>
{props.showAddCartBtn && (
<Button bottomAction text="加入购物车" onClick={emit('sku:addCart')} />
)}
<Button
type="primary"
bottomAction
text={props.buyText || '立即购买'}
onClick={emit('sku:buy')}
/>
</div>
);
}
return (
<div class={bem()}>
{this.showAddCartBtn && (
<Button bottomAction text="加入购物车" onClick={emit('sku:addCart')} />
)}
<Button
type="primary"
bottomAction
text={this.buyText || '立即购买'}
onClick={emit('sku:buy')}
/>
</div>
);
}
});
SkuActions.props = {
buyText: String,
skuEventBus: Object,
showAddCartBtn: Boolean
};
export default sfc(SkuActions);