refactor(Col): use setup

This commit is contained in:
chenjiahan 2020-08-24 15:48:43 +08:00
parent 4d9b4b3e23
commit 804a4e0193

View File

@ -15,39 +15,31 @@ export default createComponent({
}, },
}, },
emits: ['click'], setup(props, { slots }) {
return (vm) => {
const { tag, span, offset } = props;
computed: { const getStyle = () => {
style() { const { index } = vm;
const { index } = this; const { spaces } = vm.parent || {};
const { spaces } = this.parent || {};
if (spaces && spaces[index]) { if (spaces && spaces[index]) {
const { left, right } = spaces[index]; const { left, right } = spaces[index];
return { return {
paddingLeft: left ? `${left}px` : null, paddingLeft: left ? `${left}px` : null,
paddingRight: right ? `${right}px` : null, paddingRight: right ? `${right}px` : null,
}; };
} }
}, };
},
methods: { return (
onClick(event) { <tag
this.$emit('click', event); style={getStyle()}
}, class={bem({ [span]: span, [`offset-${offset}`]: offset })}
}, >
{slots.default?.()}
render() { </tag>
const { span, offset } = this; );
return ( };
<this.tag
style={this.style}
class={bem({ [span]: span, [`offset-${offset}`]: offset })}
onClick={this.onClick}
>
{this.$slots.default?.()}
</this.tag>
);
}, },
}); });