blob: 915dfa691c8faf562837c8909be7cf592c8b37b4 [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<template>
2 <view class="u-row" :style="{
3 alignItems: uAlignItem,
4 justifyContent: uJustify
5 }"
6 @tap="click"
7 >
8 <slot />
9 </view>
10</template>
11
12<script>
13 /**
14 * row 行布局
15 * @description 通过基础的 12 分栏,迅速简便地创建布局。
16 * @tutorial https://www.uviewui.com/components/layout.html#row-props
17 * @property {String Number} gutter 栅格间隔,左右各为此值的一半,单位rpx(默认0)
18 * @property {String} justify 水平排列方式(微信小程序暂不支持)默认(start(或flex-start))
19 * @property {String} align 垂直排列方式(默认center)
20 * @example <u-row gutter="16"></u-row>
21 */
22 export default {
23 name: "u-row",
24 props: {
25 // 给col添加间距,左右边距各占一半
26 gutter: {
27 type: [String, Number],
28 default: 20
29 },
30 // 水平排列方式,可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`)
31 justify: {
32 type: String,
33 default: 'start'
34 },
35 // 垂直对齐方式,可选值为top、center、bottom
36 align: {
37 type: String,
38 default: 'center'
39 },
40 // 是否阻止事件传播
41 stop: {
42 type: Boolean,
43 default: true
44 }
45 },
46 computed: {
47 uJustify() {
48 if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify;
49 else if (this.justify == 'around' || this.justify == 'between') return 'space-' + this.justify;
50 else return this.justify;
51 },
52 uAlignItem() {
53 if (this.align == 'top') return 'flex-start';
54 if (this.align == 'bottom') return 'flex-end';
55 else return this.align;
56 }
57 },
58 methods: {
59 click(e) {
60 this.$emit('click');
61 }
62 }
63 }
64</script>
65
66<style lang="scss">
67 @import "../../libs/css/style.components.scss";
68
69 .u-row {
70 // 由于微信小程序编译后奇怪的页面结构,只能使用float布局实现,flex无法实现
71 /* #ifndef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
72 @include vue-flex;
73 /* #endif */
74 flex-wrap: wrap;
75 }
76
77 .u-row:after {
78 /* #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
79 display: table;
80 clear: both;
81 content: "";
82 /* #endif */
83 }
84</style>