u-row.vue 2.1 KB

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