mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-10 14:39:45 +08:00
refactor(Row): use setup
This commit is contained in:
parent
804a4e0193
commit
6375fe5169
@ -16,25 +16,25 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
|
const getStyle = (vm) => {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (vm) => {
|
return (vm) => {
|
||||||
const { tag, span, offset } = props;
|
const { tag, span, offset } = props;
|
||||||
|
|
||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tag
|
<tag
|
||||||
style={getStyle()}
|
style={getStyle(vm)}
|
||||||
class={bem({ [span]: span, [`offset-${offset}`]: offset })}
|
class={bem({ [span]: span, [`offset-${offset}`]: offset })}
|
||||||
>
|
>
|
||||||
{slots.default?.()}
|
{slots.default?.()}
|
||||||
|
@ -20,17 +20,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
emits: ['click'],
|
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
spaces() {
|
groups() {
|
||||||
const gutter = Number(this.gutter);
|
|
||||||
|
|
||||||
if (!gutter) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const spaces = [];
|
|
||||||
const groups = [[]];
|
const groups = [[]];
|
||||||
|
|
||||||
let totalSpan = 0;
|
let totalSpan = 0;
|
||||||
@ -45,7 +36,19 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
groups.forEach((group) => {
|
return groups;
|
||||||
|
},
|
||||||
|
|
||||||
|
spaces() {
|
||||||
|
const gutter = Number(this.gutter);
|
||||||
|
|
||||||
|
if (!gutter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const spaces = [];
|
||||||
|
|
||||||
|
this.groups.forEach((group) => {
|
||||||
const averagePadding = (gutter * (group.length - 1)) / group.length;
|
const averagePadding = (gutter * (group.length - 1)) / group.length;
|
||||||
|
|
||||||
group.forEach((item, index) => {
|
group.forEach((item, index) => {
|
||||||
@ -63,27 +66,22 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
setup(props, { slots }) {
|
||||||
onClick(event) {
|
return () => {
|
||||||
this.$emit('click', event);
|
const { tag, type, align, justify } = props;
|
||||||
},
|
const flex = type === 'flex';
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
return (
|
||||||
const { align, justify } = this;
|
<tag
|
||||||
const flex = this.type === 'flex';
|
class={bem({
|
||||||
|
flex,
|
||||||
return (
|
[`align-${align}`]: flex && align,
|
||||||
<this.tag
|
[`justify-${justify}`]: flex && justify,
|
||||||
class={bem({
|
})}
|
||||||
flex,
|
>
|
||||||
[`align-${align}`]: flex && align,
|
{slots.default?.()}
|
||||||
[`justify-${justify}`]: flex && justify,
|
</tag>
|
||||||
})}
|
);
|
||||||
onClick={this.onClick}
|
};
|
||||||
>
|
|
||||||
{this.$slots.default?.()}
|
|
||||||
</this.tag>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user