wd-row.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <view :class="`wd-row ${customClass}`" :style="rowStyle">
  3. <!-- 每一行 -->
  4. <slot />
  5. </view>
  6. </template>
  7. <script lang="ts">
  8. export default {
  9. name: 'wd-row',
  10. options: {
  11. virtualHost: true,
  12. addGlobalClass: true,
  13. styleIsolation: 'shared'
  14. }
  15. }
  16. </script>
  17. <script lang="ts" setup>
  18. import { computed, type CSSProperties } from 'vue'
  19. import { useChildren } from '../composables/useChildren'
  20. import { ROW_KEY, rowProps } from './types'
  21. import { addUnit, objToStyle } from '../common/util'
  22. const props = defineProps(rowProps)
  23. const { linkChildren } = useChildren(ROW_KEY)
  24. linkChildren({ props })
  25. const rowStyle = computed(() => {
  26. const style: CSSProperties = {}
  27. const { gutter } = props
  28. if (gutter < 0) {
  29. console.error('[wot ui] warning(wd-row): attribute gutter must be greater than or equal to 0')
  30. } else if (gutter) {
  31. style.marginLeft = addUnit(gutter / 2)
  32. style.marginRight = addUnit(gutter / 2)
  33. }
  34. return `${objToStyle(style)}${props.customStyle}`
  35. })
  36. </script>
  37. <style lang="scss" scoped>
  38. @import './index.scss';
  39. </style>