refactor(Swipe): use flex layout

This commit is contained in:
chenjiahan
2020-03-22 07:48:16 +08:00
parent 3bd9ef1d4c
commit f701de9e58
6 changed files with 66 additions and 45 deletions
+20 -9
View File
@@ -12,17 +12,28 @@ export default createComponent({
};
},
computed: {
style() {
const style = {};
const { vertical, computedWidth, computedHeight } = this.parent;
if (vertical) {
style.height = `${computedHeight}px`;
} else {
style.width = `${computedWidth}px`;
}
if (this.offset) {
style.transform = `translate${vertical ? 'Y' : 'X'}(${this.offset}px)`;
}
return style;
},
},
render() {
const { vertical, computedWidth, computedHeight } = this.parent;
const style = {
width: computedWidth + 'px',
height: vertical ? computedHeight + 'px' : '100%',
transform: `translate${vertical ? 'Y' : 'X'}(${this.offset}px)`,
};
return (
<div class={bem()} style={style} {...{ on: this.$listeners }}>
<div class={bem()} style={this.style} {...{ on: this.$listeners }}>
{this.slots()}
</div>
);
+2 -1
View File
@@ -1,6 +1,7 @@
@import '../style/var';
.van-swipe-item {
float: left;
flex-shrink: 0;
width: 100%;
height: 100%;
}