u-col.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="u-col" :class="[
  3. 'u-col-' + span
  4. ]" :style="{
  5. padding: `0 ${Number(gutter)/2 + 'rpx'}`,
  6. marginLeft: 100 / 12 * offset + '%',
  7. flex: `0 0 ${100 / 12 * span}%`
  8. }">
  9. <slot></slot>
  10. </view>
  11. </template>
  12. <script>
  13. /**
  14. * col 布局单元格
  15. * @description 通过基础的 12 分栏,迅速简便地创建布局(搭配<u-row>使用)
  16. * @tutorial https://www.uviewui.com/components/layout.html
  17. * @property {String Number} span 栅格占据的列数,总12等分(默认0)
  18. * @property {String Number} offset 分栏左边偏移,计算方式与span相同(默认0)
  19. * @example <u-col span="3"><view class="demo-layout bg-purple"></view></u-col>
  20. */
  21. export default {
  22. name: "u-col",
  23. props: {
  24. // 占父容器宽度的多少等分,总分为12份
  25. span: {
  26. type: [Number, String],
  27. default: 12
  28. },
  29. // 指定栅格左侧的间隔数(总12栏)
  30. offset: {
  31. type: [Number, String],
  32. default: 0
  33. },
  34. },
  35. inject: ['gutter'],
  36. }
  37. </script>
  38. <style lang="scss">
  39. .u-col {
  40. /* #ifdef MP-WEIXIN */
  41. float: left;
  42. /* #endif */
  43. }
  44. .u-col-0 {
  45. width: 0;
  46. }
  47. .u-col-1 {
  48. width: calc(100%/12);
  49. }
  50. .u-col-2 {
  51. width: calc(100%/12 * 2);
  52. }
  53. .u-col-3 {
  54. width: calc(100%/12 * 3);
  55. }
  56. .u-col-4 {
  57. width: calc(100%/12 * 4);
  58. }
  59. .u-col-5 {
  60. width: calc(100%/12 * 5);
  61. }
  62. .u-col-6 {
  63. width: calc(100%/12 * 6);
  64. }
  65. .u-col-7 {
  66. width: calc(100%/12 * 7);
  67. }
  68. .u-col-8 {
  69. width: calc(100%/12 * 8);
  70. }
  71. .u-col-9 {
  72. width: calc(100%/12 * 9);
  73. }
  74. .u-col-10 {
  75. width: calc(100%/12 * 10);
  76. }
  77. .u-col-11 {
  78. width: calc(100%/12 * 11);
  79. }
  80. .u-col-12 {
  81. width: calc(100%/12 * 12);
  82. }
  83. </style>