cl-row.uvue 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <view
  3. class="cl-row"
  4. :class="[pt.className]"
  5. :style="{
  6. marginLeft: margin,
  7. marginRight: margin
  8. }"
  9. >
  10. <slot></slot>
  11. </view>
  12. </template>
  13. <script setup lang="ts">
  14. import { computed } from "vue";
  15. import { getUnit, parsePt } from "@/.cool";
  16. defineOptions({
  17. name: "cl-row"
  18. });
  19. // 组件属性定义
  20. const props = defineProps({
  21. // 透传样式配置
  22. pt: {
  23. type: Object,
  24. default: () => ({})
  25. },
  26. // 栅格间隔,单位px
  27. gutter: {
  28. type: Number,
  29. default: 0
  30. }
  31. });
  32. // 透传类型定义
  33. type PassThrough = {
  34. // 自定义类名
  35. className?: string;
  36. };
  37. // 解析透传配置
  38. const pt = computed(() => parsePt<PassThrough>(props.pt));
  39. // 计算栅格间距的负边距,用于抵消列的padding
  40. const margin = computed(() => `-${getUnit(props.gutter / 2)}`);
  41. // 暴露gutter属性给子组件使用
  42. defineExpose({
  43. gutter: computed(() => props.gutter)
  44. });
  45. </script>
  46. <style lang="scss" scoped>
  47. .cl-row {
  48. @apply flex flex-row flex-wrap relative overflow-visible;
  49. }
  50. </style>