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,12 +15,13 @@ 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];
@ -29,25 +30,16 @@ export default createComponent({
paddingRight: right ? `${right}px` : null, paddingRight: right ? `${right}px` : null,
}; };
} }
}, };
},
methods: {
onClick(event) {
this.$emit('click', event);
},
},
render() {
const { span, offset } = this;
return ( return (
<this.tag <tag
style={this.style} style={getStyle()}
class={bem({ [span]: span, [`offset-${offset}`]: offset })} class={bem({ [span]: span, [`offset-${offset}`]: offset })}
onClick={this.onClick}
> >
{this.$slots.default?.()} {slots.default?.()}
</this.tag> </tag>
); );
};
}, },
}); });