u-row.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. emits: ["click"],
  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',e);
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss">
  66. @import "../../libs/css/style.components.scss";
  67. .u-row {
  68. // 由于微信小程序编译后奇怪的页面结构,只能使用float布局实现,flex无法实现
  69. /* #ifndef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
  70. @include vue-flex;
  71. /* #endif */
  72. flex-wrap: wrap;
  73. }
  74. .u-row:after {
  75. /* #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
  76. display: table;
  77. clear: both;
  78. content: "";
  79. /* #endif */
  80. }
  81. </style>