1
0

tm-row.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view @click="$emit('click',$event)" :gutter="gutter" class="tm--row" :class="[preatClass]" >
  3. <view class="tm--row--body" :style="style" :class="[customClass]">
  4. <slot></slot>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. /**
  10. * 栅格排版ROW
  11. * @description 请注意,它需要配合col使用,不能单独使用。
  12. * @property {String} justify = [center|flex-start|flex-start|space-between|space-around] 横向对齐方向
  13. * @property {String} align = [center|flex-start|flex-end] 子项目纵向对齐方式。
  14. * @property {String|Number} width = [100%|auto] 宽度,可以是数字其它百分比,数字时单位为px
  15. * @property {String|Number} height = [100%|auto] 高度,可以是数字其它百分比,数字时单位为px
  16. * @property {Array} gutter = [] 默认:[0,0]左右,和上下间距。优先级别小于col组件内部的间距。
  17. * @property {String} custom-class = [] 自定义类。
  18. */
  19. export default {
  20. name:"tm-row",
  21. props:{
  22. // 自定义类。
  23. customClass: {
  24. type: String,
  25. default: ''
  26. },
  27. // 自定义类。
  28. preatClass: {
  29. type: String,
  30. default: ''
  31. },
  32. // 子项目横向对齐方式。
  33. justify:{
  34. type:String,
  35. default:'flex-start'
  36. },
  37. // 子项目纵向对齐方式。
  38. align:{
  39. type:String,
  40. default:'center'
  41. },
  42. width: {
  43. type: String | Number,
  44. default: '100%'
  45. },
  46. height: {
  47. type: String | Number,
  48. default: ""
  49. },
  50. // 左右,和上下间距。优先级别小于col组件内部的间距。
  51. gutter:{
  52. type:Array,
  53. default:()=>{
  54. return [0,0]
  55. }
  56. }
  57. },
  58. data() {
  59. return {
  60. width_px:0,
  61. children_num:0,
  62. style:'',
  63. };
  64. },
  65. updated() {
  66. this.getContinaRect()
  67. },
  68. mounted() {
  69. this.getContinaRect()
  70. },
  71. methods:{
  72. getContinaRect(){
  73. let t = this;
  74. this.$Querey('.tm--row',this).then(preantw=>{
  75. t.width_px = preantw[0].width;
  76. // #ifndef H5
  77. t.children_num = t.$children.length;
  78. // #endif
  79. // #ifdef H5
  80. t.children_num = t.$children[0].$children[0].$children[0].$children.length;
  81. // #endif
  82. t.style = uni.$tm.objToString({
  83. 'justify-content':t.justify,
  84. 'align-items':t.align,
  85. 'width':t.width,
  86. 'height':!t.height?'default':(uni.upx2px(t.height)+'px')
  87. },';');
  88. }).catch(e=>{})
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .tm--row{
  95. display: flex;
  96. flex-flow: row wrap;
  97. width: auto;
  98. .tm--row--body{
  99. height: 100%;
  100. flex-flow: row wrap;
  101. }
  102. }
  103. </style>