row.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="hc-row" :style="styleVal">
  3. <slot />
  4. </div>
  5. </template>
  6. <script>
  7. export default {name: 'HcRow'}
  8. </script>
  9. <script setup>
  10. import {onMounted, ref, watch} from "vue";
  11. const props = defineProps({
  12. //栅格间隔
  13. gutter: {
  14. type: [Number, String],
  15. default: 0,
  16. },
  17. //水平排列方式
  18. justify: {
  19. type: String,
  20. default: '',
  21. },
  22. //垂直排列方式
  23. align: {
  24. type: String,
  25. default: '',
  26. },
  27. })
  28. onMounted(() => {
  29. setStyleValue(props.gutter, props.justify, props.align)
  30. })
  31. //监听
  32. watch(() => [
  33. props.gutter,
  34. props.justify,
  35. props.align,
  36. ], ([gutter, justify, align]) => {
  37. setStyleValue(gutter, justify, align)
  38. })
  39. //处理栅格间隔
  40. const styleVal = ref({})
  41. function setStyleValue(gutter, justify, align) {
  42. const gutters = Number(gutter)
  43. styleVal.value['--hc-row-justify'] = justify ? justify : 'start'
  44. styleVal.value['--hc-row-align'] = align ? align : 'start'
  45. if (gutters !== 0) {
  46. const num = Math.floor(gutters / -2) + (gutters % 2) + 'px'
  47. styleVal.value['--hc-row-margin'] = num ? num : '0'
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. @import "./style.scss";
  53. </style>