cl-col.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view
  3. :class="['cl-col', classList]"
  4. :style="{
  5. 'padding-left': padding,
  6. 'padding-right': padding,
  7. }"
  8. @tap="onTap"
  9. >
  10. <slot></slot>
  11. </view>
  12. </template>
  13. <script>
  14. import Parent from "../../mixins/parent";
  15. /**
  16. * col 列
  17. * @description 布局组件
  18. * @tutorial https://docs.cool-js.com/uni/components/layout/flex.html
  19. * @property {Object} span 栅格占据的列数
  20. * @property {Object} offset 栅格左侧的间隔格数
  21. * @property {Boolean} pull 栅格向右移动格数
  22. * @property {Boolean} push 栅格向左移动格数
  23. * @example <cl-col :span="12"></cl-col>
  24. */
  25. export default {
  26. name: "cl-col",
  27. props: {
  28. // 栅格占据的列数
  29. span: {
  30. type: [Number, String],
  31. default: 24,
  32. },
  33. // 栅格左侧的间隔格数
  34. offset: [Number, String],
  35. // 栅格向右移动格数
  36. pull: [Number, String],
  37. // 栅格向左移动格数
  38. push: [Number, String],
  39. },
  40. mixins: [Parent],
  41. data() {
  42. return {
  43. Keys: ["gutter"],
  44. ComponentName: "ClRow",
  45. };
  46. },
  47. computed: {
  48. gutter() {
  49. return this.parent.gutter;
  50. },
  51. padding() {
  52. return this.gutter / 2 + "rpx";
  53. },
  54. classList() {
  55. let list = [];
  56. ["span", "offset", "pull", "push"].forEach((prop) => {
  57. let value = this[prop];
  58. if (value || value === 0) {
  59. list.push(prop !== "span" ? `cl-col-${prop}-${value}` : `cl-col-${value}`);
  60. }
  61. });
  62. return list.join(" ");
  63. },
  64. },
  65. methods: {
  66. onTap(e) {
  67. this.$emit("click", e);
  68. this.$emit("tap", e);
  69. },
  70. },
  71. };
  72. </script>