u-row.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="u-row" :style="{
  3. alignItems: uAlignItem,
  4. justifyContent: uJustify
  5. }"
  6. @tap.stop.prevent="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. computed: {
  41. uJustify() {
  42. if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify;
  43. else if (this.justify == 'around' || this.justify == 'between') return 'space-' + this.justify;
  44. else return this.justify;
  45. },
  46. uAlignItem() {
  47. if (this.align == 'top') return 'flex-start';
  48. if (this.align == 'bottom') return 'flex-end';
  49. else return this.align;
  50. }
  51. },
  52. methods: {
  53. click() {
  54. this.$emit('click');
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss">
  60. @import "../../libs/css/style.components.scss";
  61. .u-row {
  62. // 由于微信小程序编译后奇怪的页面结构,只能使用float布局实现,flex无法实现
  63. /* #ifndef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
  64. @include vue-flex;
  65. /* #endif */
  66. flex-wrap: wrap;
  67. }
  68. .u-row:after {
  69. /* #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
  70. display: table;
  71. clear: both;
  72. content: "";
  73. /* #endif */
  74. }
  75. </style>