vant/src-next/col/index.js
2020-07-06 15:22:33 +08:00

54 lines
1.1 KiB
JavaScript

import { createNamespace } from '../utils';
import { ChildrenMixin } from '../mixins/relation';
const [createComponent, bem] = createNamespace('col');
export default createComponent({
mixins: [ChildrenMixin('vanRow')],
props: {
span: [Number, String],
offset: [Number, String],
tag: {
type: String,
default: 'div',
},
},
emits: ['click'],
computed: {
style() {
const { index } = this;
const { spaces } = this.parent || {};
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>
);
},
});