mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-06-01 03:09:15 +08:00
refactor(Col): use setup
This commit is contained in:
parent
4d9b4b3e23
commit
804a4e0193
@ -15,39 +15,31 @@ export default createComponent({
|
||||
},
|
||||
},
|
||||
|
||||
emits: ['click'],
|
||||
setup(props, { slots }) {
|
||||
return (vm) => {
|
||||
const { tag, span, offset } = props;
|
||||
|
||||
computed: {
|
||||
style() {
|
||||
const { index } = this;
|
||||
const { spaces } = this.parent || {};
|
||||
const getStyle = () => {
|
||||
const { index } = vm;
|
||||
const { spaces } = vm.parent || {};
|
||||
|
||||
if (spaces && spaces[index]) {
|
||||
const { left, right } = spaces[index];
|
||||
return {
|
||||
paddingLeft: left ? `${left}px` : null,
|
||||
paddingRight: right ? `${right}px` : null,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
if (spaces && spaces[index]) {
|
||||
const { left, right } = spaces[index];
|
||||
return {
|
||||
paddingLeft: left ? `${left}px` : null,
|
||||
paddingRight: right ? `${right}px` : null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
methods: {
|
||||
onClick(event) {
|
||||
this.$emit('click', event);
|
||||
},
|
||||
},
|
||||
|
||||
render() {
|
||||
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>
|
||||
);
|
||||
return (
|
||||
<tag
|
||||
style={getStyle()}
|
||||
class={bem({ [span]: span, [`offset-${offset}`]: offset })}
|
||||
>
|
||||
{slots.default?.()}
|
||||
</tag>
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user